1  /-
  2  Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
  3  Released under Apache 2.0 license as described in the file LICENSE.
  4  Metric spaces.
  5  
  6  Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
  7  
  8  Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and
  9  topological spaces. For example:
 10    open and closed sets, compactness, completeness, continuity and uniform continuity
 11  -/
 12  import data.real.nnreal topology.metric_space.emetric_space topology.algebra.ordered
src         └──────────────┘ └─────────────────────────────────┘ └──────────────────────┘
 13  open lattice set filter classical topological_space
 14  noncomputable theory
 15  
 16  open_locale uniformity
 17  open_locale topological_space
 18  
 19  universes u v w
 20  variables {α : Type u} {β : Type v} {γ : Type w}
 21  
 22  /-- Construct a uniform structure from a distance function and metric space axioms -/
 23  def uniform_space_of_dist
 24    (dist : α → α → ℝ)
 25    (dist_self : ∀ x : α, dist x x = 0)
 26    (dist_comm : ∀ x y : α, dist x y = dist y x)
 27    (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space α :=
 28  uniform_space.of_core {
 29    uniformity := (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}),
 30    refl       := le_infi $ assume ε, le_infi $
 31      by simp [set.subset_def, id_rel, dist_self, (>)] {contextual := tt},
src         └────┘              └┘      └┘         └┘ └──┘ └────────────┘  
typ         └────┘              └┘      └┘         └┘ └──┘ └────────────┘  
doc         └────┘              └┘      └┘         └┘ └──┘ └────────────┘  
txt         └────┘              └┘      └┘         └┘ └──┘ └────────────┘  
par         └────┘              └┘      └┘         └┘ └──┘ └────────────┘  
pid                           └┘      └┘         └┘ └─┘ └────────────┘  
 32    comp       := le_infi $ assume ε, le_infi $ assume h, lift'_le
id                                     └─────┘            └──────┘
src                                     └─────┘             └──────┘
typ                                    └─────┘            └──────┘
 33      (mem_infi_sets (ε / 2) $ mem_infi_sets (div_pos_of_pos_of_pos h two_pos) (subset.refl _)) $
id        └───────────┘         └───────────┘  └───────────────────┘  └─────┘   └─────────┘
src       └───────────┘          └───────────┘  └───────────────────┘   └─────┘   └─────────┘
typ       └───────────┘         └───────────┘  └───────────────────┘  └─────┘   └─────────┘
 34      have ∀ (a b c : α), dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε,
id                          └──┘          └──┘          └──┘    
src                                                                     
typ                         └──┘          └──┘          └──┘    
 35        from assume a b c hac hcb,
id                        └─┘ └─┘
typ                       └─┘ └─┘
 36        calc dist a b ≤ dist a c + dist c b : dist_triangle _ _ _
id              └──┘     └──┘    └──┘     └───────────┘
src                                 
typ             └──┘     └──┘    └──┘     └───────────┘
 37          ... < ε / 2 + ε / 2 : add_lt_add hac hcb
id                            └────────┘ └─┘ └─┘
src                             └────────┘
typ                           └────────┘ └─┘ └─┘
 38          ... = ε : by rw [div_add_div_same, add_self_div_two],
id                           └──────────────┘  └──────────────┘
src                       └──┘└──────────────┘└┘└──────────────┘
typ                      └──┘└──────────────┘└┘└──────────────┘
doc                       └──┘                └┘                
txt                       └──┘                └┘                
par                       └──┘                └┘                
pid                         └┘                └┘                
st                       └───────────────────┘└────────────────┘
 39      by simpa [comp_rel],
id                 └──────┘
src         └─────┘└──────┘
typ         └─────┘└──────┘
doc         └─────┘└──────┘
txt         └─────┘        
par         └─────┘        
pid                      
st         └───────────────┘
 40    symm       := tendsto_infi.2 $ assume ε, tendsto_infi.2 $ assume h,
id                   └──────────┘             └──────────┘           
src                  └──────────┘              └──────────┘
typ                  └──────────┘             └──────────┘           
 41      tendsto_infi' ε $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [dist_comm] }
id       └───────────┘    └───────────┘    └─────────────────────────┘             └───────┘
src      └───────────┘     └───────────┘     └─────────────────────────┘       └────┘         └┘
typ      └───────────┘    └───────────┘    └─────────────────────────┘       └────┘└───────┘└┘
doc                                                                             └────┘         └┘
txt                                                                             └────┘         └┘
par                                                                             └────┘         └┘
pid                                                                                          
st                                                                             └────────────────┘
 42  
 43  /-- The distance function (given an ambient metric space on `α`), which returns
 44    a nonnegative real number `dist x y` given `x y : α`. -/
 45  class has_dist (α : Type*) := (dist : α → α → ℝ)
id                       └───┘                  
src                                                
typ                      └───┘                  
 46  
 47  export has_dist (dist)
 48  
 49  section prio
 50  set_option default_priority 100 -- see Note [default priority]
doc             └──────────────┘
 51  /-- Metric space
 52  
 53  Each metric space induces a canonical `uniform_space` and hence a canonical `topological_space`.
 54  This is enforced in the type class definition, by extending the `uniform_space` structure. When
 55  instantiating a `metric_space` structure, the uniformity fields are not necessary, they will be
 56  filled in by default. In the same way, each metric space induces an emetric space structure.
 57  It is included in the structure, but filled in by default.
 58  
 59  When one instantiates a metric space structure, for instance a product structure,
 60  this makes it possible to use a uniform structure and an edistance that are exactly
 61  the ones for the uniform spaces product and the emetric spaces products, thereby
 62  ensuring that everything in defeq in diamonds.-/
 63  class metric_space (α : Type u) extends has_dist α : Type u :=
id                           └──┘            └──────┘ 
src                                          └──────┘
typ                          └──┘            └──────┘ 
doc                                          └──────┘
 64  (dist_self : ∀ x : α, dist x x = 0)
id                       └──┘   
src                                 
typ                      └──┘   
 65  (eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
id                                    └──┘          
src                                                     
typ                                   └──┘          
 66  (dist_comm : ∀ x y : α, dist x y = dist y x)
id                         └──┘    └──┘  
src                                   
typ                        └──┘    └──┘  
 67  (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
id                               └──┘    └──┘    └──┘  
src                                                   
typ                              └──┘    └──┘    └──┘  
 68  (edist : α → α → ennreal := λx y, ennreal.of_real (dist x y))
id                 └─────┘        └─────────────┘  └──┘  
src                   └─────┘          └─────────────┘
typ                └─────┘        └─────────────┘  └──┘  
doc                   └─────┘          └─────────────┘
 69  (edist_dist : ∀ x y : α, edist x y = ennreal.of_real (dist x y) . control_laws_tac)
id                          └───┘    └─────────────┘  └──┘  
src                                     └─────────────┘
typ                         └───┘    └─────────────┘  └──┘  
doc                                      └─────────────┘
 70  (to_uniform_space : uniform_space α := uniform_space_of_dist dist dist_self dist_comm dist_triangle)
id                       └───────────┘     └───────────────────┘ └──┘ └───────┘ └───────┘ └───────────┘
src                      └───────────┘      └───────────────────┘
typ                      └───────────┘     └───────────────────┘ └──┘ └───────┘ └───────┘ └───────────┘
doc                      └───────────┘      └───────────────────┘
 71  (uniformity_dist : 𝓤 α = ⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε} . control_laws_tac)
id                             └───────┘      └──┘      
src                              └───────┘                   
typ                            └───────┘      └──┘      
doc                              └───────┘
 72  end prio
 73  
 74  variables [metric_space α]
id              └──────────┘
src             └──────────┘
typ             └──────────┘
doc             └──────────┘
 75  
 76  @[priority 100] -- see Note [lower instance priority]
 77  instance metric_space.to_uniform_space' : uniform_space α :=
id                                             └───────────┘ 
src                                            └───────────┘
typ                                            └───────────┘ 
doc                                            └───────────┘
 78  metric_space.to_uniform_space α
id   └───────────────────────────┘ 
src  └───────────────────────────┘
typ  └───────────────────────────┘ 
 79  
 80  @[priority 200] -- see Note [lower instance priority]
 81  instance metric_space.to_has_edist : has_edist α := ⟨metric_space.edist⟩
id                                        └───────┘      └────────────────┘
src                                       └───────┘       └────────────────┘
typ                                       └───────┘      └────────────────┘
 82  
 83  @[simp] theorem dist_self (x : α) : dist x x = 0 := metric_space.dist_self x
id                                      └──┘         └────────────────────┘ 
src                                      └──┘           └────────────────────┘
typ                                     └──┘         └────────────────────┘ 
doc    └──┘
 84  
 85  theorem eq_of_dist_eq_zero {x y : α} : dist x y = 0 → x = y :=
id                                         └──┘          
src                                         └──┘            
typ                                        └──┘          
 86  metric_space.eq_of_dist_eq_zero
id   └─────────────────────────────┘
src  └─────────────────────────────┘
typ  └─────────────────────────────┘
 87  
 88  theorem dist_comm (x y : α) : dist x y = dist y x := metric_space.dist_comm x y
id                                └──┘    └──┘      └────────────────────┘  
src                                └──┘      └──┘        └────────────────────┘
typ                               └──┘    └──┘      └────────────────────┘  
 89  
 90  theorem edist_dist (x y : α) : edist x y = ennreal.of_real (dist x y) :=
id                                 └───┘    └─────────────┘  └──┘  
src                                 └───┘      └─────────────┘  └──┘
typ                                └───┘    └─────────────┘  └──┘  
doc                                             └─────────────┘
 91  metric_space.edist_dist _ x y
id   └─────────────────────┘    
src  └─────────────────────┘
typ  └─────────────────────┘    
 92  
 93  @[simp] theorem dist_eq_zero {x y : α} : dist x y = 0 ↔ x = y :=
id                                           └──┘         
src                                           └──┘           
typ                                          └──┘         
doc    └──┘
 94  iff.intro eq_of_dist_eq_zero (assume : x = y, this ▸ dist_self _)
id   └───────┘ └────────────────┘               └──┘  └───────┘
src  └───────┘ └────────────────┘                       └───────┘
typ  └───────┘ └────────────────┘               └──┘  └───────┘
 95  
 96  @[simp] theorem zero_eq_dist {x y : α} : 0 = dist x y ↔ x = y :=
id                                              └──┘      
src                                              └──┘        
typ                                             └──┘      
doc    └──┘
 97  by rw [eq_comm, dist_eq_zero]
id          └─────┘  └──────────┘
src     └──┘└─────┘└┘└──────────┘└─
typ     └──┘└─────┘└┘└──────────┘└─
doc     └──┘       └┘            └─
txt     └──┘       └┘            └─
par     └──┘       └┘            └─
pid       └┘       └┘            
st     └──────────┘└────────────┘
 98  
src  
typ  
doc  
txt  
par  
pid  
st   
 99  theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
id                                      └──┘    └──┘    └──┘  
src                                      └──┘      └──┘      └──┘
typ                                     └──┘    └──┘    └──┘  
100  metric_space.dist_triangle x y z
id   └────────────────────────┘   
src  └────────────────────────┘
typ  └────────────────────────┘   
101  
102  theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y :=
id                                           └──┘    └──┘    └──┘  
src                                           └──┘      └──┘      └──┘
typ                                          └──┘    └──┘    └──┘  
103  by rw dist_comm z; apply dist_triangle
id         └───────┘         └───────────┘
src     └─┘└───────┘   └────┘└───────────┘
typ     └─┘└───────┘  └────┘└───────────┘
doc     └─┘            └────┘             
txt     └─┘            └────┘             
par     └─┘            └────┘             
pid                                     
st     └────────────────────────────────────
104  
src  
typ  
doc  
txt  
par  
pid  
st   
105  theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z :=
id                                            └──┘    └──┘    └──┘  
src                                            └──┘      └──┘      └──┘
typ                                           └──┘    └──┘    └──┘  
106  by rw dist_comm y; apply dist_triangle
id         └───────┘         └───────────┘
src     └─┘└───────┘   └────┘└───────────┘
typ     └─┘└───────┘  └────┘└───────────┘
doc     └─┘            └────┘             
txt     └─┘            └────┘             
par     └─┘            └────┘             
pid                                     
st     └────────────────────────────────────
107  
src  
typ  
doc  
txt  
par  
pid  
st   
108  lemma dist_triangle4 (x y z w : α) :
id                                   
typ                                  
109    dist x w ≤ dist x y + dist y z + dist z w :=
id     └──┘    └──┘    └──┘    └──┘  
src    └──┘      └──┘      └──┘      └──┘
typ    └──┘    └──┘    └──┘    └──┘  
110  calc
111    dist x w ≤ dist x z + dist z w : dist_triangle x z w
id     └──┘     └──┘    └──┘     └───────────┘   
src    └──┘       └──┘      └──┘       └───────────┘
typ    └──┘     └──┘    └──┘     └───────────┘   
112         ... ≤ (dist x y + dist y z) + dist z w : add_le_add_right (metric_space.dist_triangle x y z) _
id                 └──┘    └──┘     └──┘     └──────────────┘  └────────────────────────┘   
src                └──┘      └──┘       └──┘       └──────────────┘  └────────────────────────┘
typ                └──┘    └──┘     └──┘     └──────────────┘  └────────────────────────┘   
113  
114  lemma dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :
id                                            
typ                                           
115    dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) :=
id     └──┘ └┘ └┘  └──┘ └┘ └┘   └──┘ └┘ └┘  └──┘ └┘ └┘
src    └──┘        └──┘         └──┘        └──┘
typ    └──┘ └┘ └┘  └──┘ └┘ └┘   └──┘ └┘ └┘  └──┘ └┘ └┘
116  by rw [add_left_comm, dist_comm x₁, ← add_assoc]; apply dist_triangle4
id          └───────────┘  └───────┘ └┘    └───────┘         └────────────┘
src     └──┘└───────────┘└┘└───────┘  └──┘└───────┘  └────┘└────────────┘
typ     └──┘└───────────┘└┘└───────┘└┘└──┘└───────┘  └────┘└────────────┘
doc     └──┘             └┘           └──┘           └────┘              
txt     └──┘             └┘           └──┘           └────┘              
par     └──┘             └┘           └──┘           └────┘              
pid       └┘             └┘           └──┘                              
st     └────────────────┘└────────────┘└───────────┘└──────────────────────
117  
src  
typ  
doc  
txt  
par  
pid  
st   
118  lemma dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :
id                                             
typ                                            
119    dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ :=
id     └──┘ └┘ └┘  └──┘ └┘ └┘  └──┘ └┘ └┘  └──┘ └┘ └┘
src    └──┘        └──┘        └──┘        └──┘
typ    └──┘ └┘ └┘  └──┘ └┘ └┘  └──┘ └┘ └┘  └──┘ └┘ └┘
120  by rw [add_right_comm, dist_comm y₁]; apply dist_triangle4
id          └────────────┘  └───────┘ └┘         └────────────┘
src     └──┘└────────────┘└┘└───────┘    └────┘└────────────┘
typ     └──┘└────────────┘└┘└───────┘└┘  └────┘└────────────┘
doc     └──┘              └┘             └────┘              
txt     └──┘              └┘             └────┘              
par     └──┘              └┘             └────┘              
pid       └┘              └┘                                
st     └─────────────────┘└────────────┘└──────────────────────
121  
src  
typ  
doc  
txt  
par  
pid  
st   
122  /-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
123  lemma dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) :
id                                                     
src                                                     
typ                                                    
124    dist (f m) (f n) ≤ (finset.Ico m n).sum (λ i, dist (f i) (f (i + 1))) :=
id     └──┘           └────────┘   └─┘       └──┘         
src    └──┘               └────────┘     └─┘        └──┘             
typ    └──┘           └────────┘   └─┘       └──┘         
doc                        └────────┘
125  begin
st   └─────
126    revert n,
src    └──────┘
typ    └──────┘
doc    └──────┘
txt    └──────┘
par    └──────┘
pid          └┘
st   ─────────┘└─
127    apply nat.le_induction,
id           └──────────────┘
src    └────┘└──────────────┘
typ    └────┘└──────────────┘
doc    └────┘└──────────────┘
txt    └────┘
par    └────┘
pid         
st   ───────────────────────┘└─
128    { simp only [finset.sum_empty, finset.Ico.self_eq_empty, dist_self] },
id                  └──────────────┘  └──────────────────────┘  └───────┘
src      └─────────┘└──────────────┘└┘└──────────────────────┘└┘└───────┘└┘
typ      └─────────┘└──────────────┘└┘└──────────────────────┘└┘└───────┘└┘
doc      └─────────┘                └┘                        └┘         └┘
txt      └─────────┘                └┘                        └┘         └┘
par      └─────────┘                └┘                        └┘         └┘
pid          └──┘└┘                └┘                        └┘         
st   ───┘└────────────────────────────────────────────────────────────────┘└┘
129    { assume n hn hrec,
src      └──────────────┘
typ      └──────────────┘
doc      └──────────────┘
txt      └──────────────┘
par      └──────────────┘
pid      └──────────────┘
st   ───────────────────┘└─
130      calc dist (f m) (f (n+1)) ≤ dist (f m) (f n) + dist _ _ : dist_triangle _ _ _
id       └──┘                                       └──┘       └───────────┘
src      └──┘                                          └──┘       └───────────┘
typ      └──┘                                       └──┘       └───────────┘
doc      └──┘
st   ──────────────────────────────────────────────────────────────────────────────────
131        ... ≤ (finset.Ico m n).sum _ + _ : add_le_add hrec (le_refl _)
id                               └─┘          └────────┘ └──┘  └─────┘
src                              └─┘          └────────┘       └─────┘
typ                              └─┘          └────────┘ └──┘  └─────┘
st   ─────────────────────────────────────────────────────────────────────
132        ... = (finset.Ico m (n+1)).sum _ :
id                └────────┘         └─┘
src               └────────┘         └─┘
typ               └────────┘         └─┘
doc               └────────┘
st   ─────────────────────────────────────────
133          by rw [finset.Ico.succ_top hn, finset.sum_insert, add_comm]; simp }
id                  └─────────────────┘ └┘  └───────────────┘  └──────┘
src             └──┘└─────────────────┘  └┘└───────────────┘└┘└──────┘  └───┘
typ             └──┘└─────────────────┘└┘└┘└───────────────┘└┘└──────┘  └───┘
doc             └──┘                     └┘                 └┘          └───┘
txt             └──┘                     └┘                 └┘          └───┘
par             └──┘                     └┘                 └┘          └───┘
pid               └┘                     └┘                 └┘              
st   ─────────┘└─────────────────────────┘└─────────────────┘└────────┘└─────┘└─
134  end
st   ──┘
135  
136  /-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
137  lemma dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) :
id                                               
src                                               
typ                                              
138    dist (f 0) (f n) ≤ (finset.range n).sum (λ i, dist (f i) (f (i + 1))) :=
id     └──┘            └──────────┘  └─┘       └──┘         
src    └──┘               └──────────┘   └─┘        └──┘             
typ    └──┘            └──────────┘  └─┘       └──┘         
doc                        └──────────┘
139  finset.Ico.zero_bot n ▸ dist_le_Ico_sum_dist f (nat.zero_le n)
id   └─────────────────┘   └──────────────────┘   └─────────┘ 
src  └─────────────────┘    └──────────────────┘    └─────────┘
typ  └─────────────────┘   └──────────────────┘   └─────────┘ 
doc                          └──────────────────┘
140  
141  /-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced
142  with an upper estimate. -/
143  lemma dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n)
id                                                             
src                                                             
typ                                                            
144    {d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) :
id                                     └──┘                
src                                         └──┘                  
typ                                    └──┘                
145    dist (f m) (f n) ≤ (finset.Ico m n).sum d :=
id     └──┘           └────────┘   └─┘  
src    └──┘               └────────┘     └─┘
typ    └──┘           └────────┘   └─┘  
doc                        └────────┘
146  le_trans (dist_le_Ico_sum_dist f hmn) $
id   └──────┘  └──────────────────┘  └─┘
src  └──────┘  └──────────────────┘
typ  └──────┘  └──────────────────┘  └─┘
doc            └──────────────────┘
147  finset.sum_le_sum $ λ k hk, hd (finset.Ico.mem.1 hk).1 (finset.Ico.mem.1 hk).2
id   └───────────────┘      └┘  └┘  └────────────┘  └┘    └────────────┘  └┘ 
src  └───────────────┘               └────────────┘        └────────────┘     
typ  └───────────────┘      └┘  └┘  └────────────┘  └┘    └────────────┘  └┘ 
148  
149  /-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced
150  with an upper estimate. -/
151  lemma dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ)
id                                                     
src                                                     
typ                                                    
152    {d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) :
id                                └──┘                
src                                  └──┘                  
typ                               └──┘                
153    dist (f 0) (f n) ≤ (finset.range n).sum d :=
id     └──┘            └──────────┘  └─┘  
src    └──┘               └──────────┘   └─┘
typ    └──┘            └──────────┘  └─┘  
doc                        └──────────┘
154  finset.Ico.zero_bot n ▸ dist_le_Ico_sum_of_dist_le (zero_le n) (λ _ _, hd)
id   └─────────────────┘   └────────────────────────┘  └─────┘         └┘
src  └─────────────────┘    └────────────────────────┘  └─────┘
typ  └─────────────────┘   └────────────────────────┘  └─────┘         └┘
doc                          └────────────────────────┘
155  
156  theorem swap_dist : function.swap (@dist α _) = dist :=
id                       └───────────┘   └──┘      └──┘
src                      └───────────┘   └──┘       └──┘
typ                      └───────────┘   └──┘      └──┘
157  by funext x y; exact dist_comm _ _
id                        └───────┘
src     └────────┘  └────┘└───────┘└────
typ     └────────┘  └────┘└───────┘└────
doc     └────────┘  └────┘         └────
txt     └────────┘  └────┘         └────
par     └────────┘  └────┘         └────
pid           └──┘                └──┘
st     └────────────────────────────────
158  
src  
typ  
doc  
txt  
par  
pid  
st   
159  theorem abs_dist_sub_le (x y z : α) : abs (dist x z - dist y z) ≤ dist x y :=
id                                        └─┘  └──┘    └──┘     └──┘  
src                                        └─┘  └──┘      └──┘       └──┘
typ                                       └─┘  └──┘    └──┘     └──┘  
160  abs_sub_le_iff.2
id   └────────────┘
src  └────────────┘
typ  └────────────┘
161   ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _),
id     └───────────────┘   └───────────┘
src    └───────────────┘   └───────────┘
typ    └───────────────┘   └───────────┘
162    sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
id     └───────────────┘   └────────────────┘
src    └───────────────┘   └────────────────┘
typ    └───────────────┘   └────────────────┘
163  
164  theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
id                                     └──┘  
src                                     └──┘
typ                                    └──┘  
165  have 2 * dist x y ≥ 0,
id           └──┘   
src          └──┘     
typ          └──┘   
166    from calc 2 * dist x y = dist x y + dist y x : by rw [dist_comm x y, two_mul]
id                  └──┘     └──┘    └──┘            └───────┘    └─────┘
src                 └──┘       └──┘      └──┘          └──┘└───────┘  └┘└─────┘└─
typ                 └──┘     └──┘    └──┘        └──┘└───────┘└┘└─────┘└─
doc                                                      └──┘           └┘       └─
txt                                                      └──┘           └┘       └─
par                                                      └──┘           └┘       └─
pid                                                        └┘           └┘       
st                                                      └────────────────┘└───────┘
167      ... ≥ 0 : by rw ← dist_self x; apply dist_triangle,
id                         └───────┘         └───────────┘
src  ───┘             └───┘└───────┘   └────┘└───────────┘
typ  ───┘             └───┘└───────┘  └────┘└───────────┘
doc  ───┘             └───┘            └────┘
txt  ───┘             └───┘            └────┘
par  ───┘             └───┘            └────┘
pid  ───┘               └─┘                 
st   ───┘            └────────────────────────────────────┘
168  nonneg_of_mul_nonneg_left this two_pos
id   └───────────────────────┘ └──┘ └─────┘
src  └───────────────────────┘      └─────┘
typ  └───────────────────────┘ └──┘ └─────┘
169  
170  @[simp] theorem dist_le_zero {x y : α} : dist x y ≤ 0 ↔ x = y :=
id                                           └──┘         
src                                           └──┘           
typ                                          └──┘         
doc    └──┘
171  by simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y
id             └─────────────┘  └─────────┘         └──────────┘      
src     └─────┘└─────────────┘└┘└─────────┘└──────┘ └──────────┘└───┘  
typ     └─────┘└─────────────┘└┘└─────────┘└──────┘ └──────────┘└───┘
doc     └─────┘               └┘           └──────┘             └───┘  
txt     └─────┘               └┘           └──────┘             └───┘  
par     └─────┘               └┘           └──────┘             └───┘  
pid                         └┘           └────┘             └───┘  
st     └─────────────────────────────────────────────────────────────────
172  
src  
typ  
doc  
txt  
par  
pid  
st   
173  @[simp] theorem dist_pos {x y : α} : 0 < dist x y ↔ x ≠ y :=
id                                          └──┘      
src                                          └──┘        
typ                                         └──┘      
doc    └──┘
174  by simpa [-dist_le_zero] using not_congr (@dist_le_zero _ _ x y)
id                                  └───────┘   └──────────┘      
src     └──────────────────────────┘└───────┘  └──────────┘└───┘  └─
typ     └──────────────────────────┘└───────┘  └──────────┘└───┘└─
doc     └──────────────────────────┘                       └───┘  └─
txt     └──────────────────────────┘                       └───┘  └─
par     └──────────────────────────┘                       └───┘  └─
pid          └─────────────┘└────┘                       └───┘  
st     └──────────────────────────────────────────────────────────────
175  
src  
typ  
doc  
txt  
par  
pid  
st   
176  @[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b :=
id                                       └─┘  └──┘     └──┘  
src                                       └─┘  └──┘       └──┘
typ                                      └─┘  └──┘     └──┘  
doc    └──┘
177  abs_of_nonneg dist_nonneg
id   └───────────┘ └─────────┘
src  └───────────┘ └─────────┘
typ  └───────────┘ └─────────┘
178  
179  theorem eq_of_forall_dist_le {x y : α} (h : ∀ε, ε > 0 → dist x y ≤ ε) : x = y :=
id                                                       └──┘          
src                                                         └──┘             
typ                                                      └──┘          
180  eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)
id   └────────────────┘  └────────────────────────────┘ └─────────┘ 
src  └────────────────┘  └────────────────────────────┘ └─────────┘
typ  └────────────────┘  └────────────────────────────┘ └─────────┘ 
181  
182  /-- Distance as a nonnegative real number. -/
183  def nndist (a b : α) : nnreal := ⟨dist a b, dist_nonneg⟩
id                         └────┘     └──┘    └─────────┘
src                         └────┘     └──┘      └─────────┘
typ                        └────┘     └──┘    └─────────┘
doc                         └────┘
184  
185  /--Express `nndist` in terms of `edist`-/
186  lemma nndist_edist (x y : α) : nndist x y = (edist x y).to_nnreal :=
id                                 └────┘     └───┘   └───────┘
src                                 └────┘       └───┘     └───────┘
typ                                └────┘     └───┘   └───────┘
doc                                 └────┘                  └───────┘
187  by simp [nndist, edist_dist, nnreal.of_real, max_eq_left dist_nonneg, ennreal.of_real]
id            └────┘  └────────┘  └────────────┘  └─────────┘ └─────────┘  └─────────────┘
src     └────┘└────┘└┘└────────┘└┘└────────────┘└┘└─────────┘└─────────┘└┘└─────────────┘└─
typ     └────┘└────┘└┘└────────┘└┘└────────────┘└┘└─────────┘└─────────┘└┘└─────────────┘└─
doc     └────┘└────┘└┘          └┘              └┘                      └┘└─────────────┘└─
txt     └────┘      └┘          └┘              └┘                      └┘               └─
par     └────┘      └┘          └┘              └┘                      └┘               └─
pid               └┘          └┘              └┘                      └┘               
st     └────────────────────────────────────────────────────────────────────────────────────
188  
src  
typ  
doc  
txt  
par  
pid  
st   
189  /--Express `edist` in terms of `nndist`-/
190  lemma edist_nndist (x y : α) : edist x y = ↑(nndist x y) :=
id                                 └───┘     └────┘  
src                                 └───┘       └────┘
typ                                └───┘     └────┘  
doc                                               └────┘
191  by { rw [edist_dist, nndist, ennreal.of_real_eq_coe_nnreal] }
id            └────────┘  └────┘  └───────────────────────────┘
src       └──┘└────────┘└┘└────┘└┘└───────────────────────────┘└┘
typ       └──┘└────────┘└┘└────┘└┘└───────────────────────────┘└┘
doc       └──┘          └┘└────┘└┘                             └┘
txt       └──┘          └┘      └┘                             └┘
par       └──┘          └┘      └┘                             └┘
pid         └┘          └┘      └┘                             
st     └───────────────┘└──────┘└─────────────────────────────┘└┘
192  
193  /--In a metric space, the extended distance is always finite-/
194  lemma edist_ne_top (x y : α) : edist x y ≠ ⊤ :=
id                                 └───┘    
src                                 └───┘      
typ                                └───┘    
195  by rw [edist_dist x y]; apply ennreal.coe_ne_top
id          └────────┘           └────────────────┘
src     └──┘└────────┘    └────┘└────────────────┘
typ     └──┘└────────┘  └────┘└────────────────┘
doc     └──┘              └────┘                  
txt     └──┘              └────┘                  
par     └──┘              └────┘                  
pid       └┘                                     
st     └─────────────────┘└──────────────────────────
196  
src  
typ  
doc  
txt  
par  
pid  
st   
197  /--In a metric space, the extended distance is always finite-/
198  lemma edist_lt_top {α : Type*} [metric_space α] (x y : α) : edist x y < ⊤ :=
id                                   └──────────┘              └───┘    
src                                  └──────────┘                └───┘      
typ                                  └──────────┘              └───┘    
doc                                  └──────────┘
199  ennreal.lt_top_iff_ne_top.2 (edist_ne_top x y)
id   └───────────────────────┘   └──────────┘  
src  └───────────────────────┘   └──────────┘
typ  └───────────────────────┘   └──────────┘  
doc                               └──────────┘
200  
201  /--`nndist x x` vanishes-/
202  @[simp] lemma nndist_self (a : α) : nndist a a = 0 := (nnreal.coe_eq_zero _).1 (dist_self a)
id                                      └────┘          └────────────────┘      └───────┘ 
src                                      └────┘            └────────────────┘      └───────┘
typ                                     └────┘          └────────────────┘      └───────┘ 
doc    └──┘                              └────┘
203  
204  /--Express `dist` in terms of `nndist`-/
205  lemma dist_nndist (x y : α) : dist x y = ↑(nndist x y) := rfl
id                                └──┘     └────┘       └─┘
src                                └──┘       └────┘         └─┘
typ                               └──┘     └────┘       └─┘
doc                                             └────┘
206  
207  /--Express `nndist` in terms of `dist`-/
208  lemma nndist_dist (x y : α) : nndist x y = nnreal.of_real (dist x y) :=
id                                └────┘    └────────────┘  └──┘  
src                                └────┘      └────────────┘  └──┘
typ                               └────┘    └────────────┘  └──┘  
doc                                └────┘
209  by rw [dist_nndist, nnreal.of_real_coe]
id          └─────────┘  └────────────────┘
src     └──┘└─────────┘└┘└────────────────┘└─
typ     └──┘└─────────┘└┘└────────────────┘└─
doc     └──┘└─────────┘└┘                  └─
txt     └──┘           └┘                  └─
par     └──┘           └┘                  └─
pid       └┘           └┘                  
st     └──────────────┘└──────────────────┘
210  
src  
typ  
doc  
txt  
par  
pid  
st   
211  /--Deduce the equality of points with the vanishing of the nonnegative distance-/
212  theorem eq_of_nndist_eq_zero {x y : α} : nndist x y = 0 → x = y :=
id                                           └────┘          
src                                           └────┘            
typ                                          └────┘          
doc                                           └────┘
213  by simp only [nnreal.eq_iff.symm, (dist_nndist _ _).symm, imp_self, nnreal.coe_zero, dist_eq_zero]
id                                      └─────────┘            └──────┘  └─────────────┘  └──────────┘
src     └─────────┘                  └┘ └─────────┘└──────────┘└──────┘└┘└─────────────┘└┘└──────────┘└─
typ     └─────────┘└────────────────┘└┘ └─────────┘└──────────┘└──────┘└┘└─────────────┘└┘└──────────┘└─
doc     └─────────┘                  └┘ └─────────┘└──────────┘        └┘               └┘            └─
txt     └─────────┘                  └┘            └──────────┘        └┘               └┘            └─
par     └─────────┘                  └┘            └──────────┘        └┘               └┘            └─
pid         └──┘└┘                  └┘            └──────────┘        └┘               └┘            
st     └────────────────────────────────────────────────────────────────────────────────────────────────
214  
src  
typ  
doc  
txt  
par  
pid  
st   
215  theorem nndist_comm (x y : α) : nndist x y = nndist y x :=
id                                  └────┘    └────┘  
src                                  └────┘      └────┘
typ                                 └────┘    └────┘  
doc                                  └────┘       └────┘
216  by simpa [nnreal.eq_iff.symm] using dist_comm x y
id                                       └───────┘  
src     └─────┘                  └──────┘└───────┘  
typ     └─────┘└────────────────┘└──────┘└───────┘
doc     └─────┘                  └──────┘           
txt     └─────┘                  └──────┘           
par     └─────┘                  └──────┘           
pid                            └────┘           
st     └───────────────────────────────────────────────
217  
src  
typ  
doc  
txt  
par  
pid  
st   
218  /--Characterize the equality of points with the vanishing of the nonnegative distance-/
219  @[simp] theorem nndist_eq_zero {x y : α} : nndist x y = 0 ↔ x = y :=
id                                             └────┘         
src                                             └────┘           
typ                                            └────┘         
doc    └──┘                                     └────┘
220  by simp only [nnreal.eq_iff.symm, (dist_nndist _ _).symm, imp_self, nnreal.coe_zero, dist_eq_zero]
id                                      └─────────┘            └──────┘  └─────────────┘  └──────────┘
src     └─────────┘                  └┘ └─────────┘└──────────┘└──────┘└┘└─────────────┘└┘└──────────┘└─
typ     └─────────┘└────────────────┘└┘ └─────────┘└──────────┘└──────┘└┘└─────────────┘└┘└──────────┘└─
doc     └─────────┘                  └┘ └─────────┘└──────────┘        └┘               └┘            └─
txt     └─────────┘                  └┘            └──────────┘        └┘               └┘            └─
par     └─────────┘                  └┘            └──────────┘        └┘               └┘            └─
pid         └──┘└┘                  └┘            └──────────┘        └┘               └┘            
st     └────────────────────────────────────────────────────────────────────────────────────────────────
221  
src  
typ  
doc  
txt  
par  
pid  
st   
222  @[simp] theorem zero_eq_nndist {x y : α} : 0 = nndist x y ↔ x = y :=
id                                                └────┘      
src                                                └────┘        
typ                                               └────┘      
doc    └──┘                                         └────┘
223  by simp only [nnreal.eq_iff.symm, (dist_nndist _ _).symm, imp_self, nnreal.coe_zero, zero_eq_dist]
id                                      └─────────┘            └──────┘  └─────────────┘  └──────────┘
src     └─────────┘                  └┘ └─────────┘└──────────┘└──────┘└┘└─────────────┘└┘└──────────┘└─
typ     └─────────┘└────────────────┘└┘ └─────────┘└──────────┘└──────┘└┘└─────────────┘└┘└──────────┘└─
doc     └─────────┘                  └┘ └─────────┘└──────────┘        └┘               └┘            └─
txt     └─────────┘                  └┘            └──────────┘        └┘               └┘            └─
par     └─────────┘                  └┘            └──────────┘        └┘               └┘            └─
pid         └──┘└┘                  └┘            └──────────┘        └┘               └┘            
st     └────────────────────────────────────────────────────────────────────────────────────────────────
224  
src  
typ  
doc  
txt  
par  
pid  
st   
225  /--Triangle inequality for the nonnegative distance-/
226  theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
id                                        └────┘    └────┘    └────┘  
src                                        └────┘      └────┘      └────┘
typ                                       └────┘    └────┘    └────┘  
doc                                        └────┘       └────┘       └────┘
227  by simpa [nnreal.coe_le] using dist_triangle x y z
id             └───────────┘        └───────────┘   
src     └─────┘└───────────┘└──────┘└───────────┘   
typ     └─────┘└───────────┘└──────┘└───────────┘
doc     └─────┘             └──────┘                
txt     └─────┘             └──────┘                
par     └─────┘             └──────┘                
pid                       └────┘                
st     └────────────────────────────────────────────────
228  
src  
typ  
doc  
txt  
par  
pid  
st   
229  theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
id                                             └────┘    └────┘    └────┘  
src                                             └────┘      └────┘      └────┘
typ                                            └────┘    └────┘    └────┘  
doc                                             └────┘       └────┘       └────┘
230  by simpa [nnreal.coe_le] using dist_triangle_left x y z
id             └───────────┘        └────────────────┘   
src     └─────┘└───────────┘└──────┘└────────────────┘   
typ     └─────┘└───────────┘└──────┘└────────────────┘
doc     └─────┘             └──────┘                     
txt     └─────┘             └──────┘                     
par     └─────┘             └──────┘                     
pid                       └────┘                     
st     └─────────────────────────────────────────────────────
231  
src  
typ  
doc  
txt  
par  
pid  
st   
232  theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
id                                              └────┘    └────┘    └────┘  
src                                              └────┘      └────┘      └────┘
typ                                             └────┘    └────┘    └────┘  
doc                                              └────┘       └────┘       └────┘
233  by simpa [nnreal.coe_le] using dist_triangle_right x y z
id             └───────────┘        └─────────────────┘   
src     └─────┘└───────────┘└──────┘└─────────────────┘   
typ     └─────┘└───────────┘└──────┘└─────────────────┘
doc     └─────┘             └──────┘                      
txt     └─────┘             └──────┘                      
par     └─────┘             └──────┘                      
pid                       └────┘                      
st     └──────────────────────────────────────────────────────
234  
src  
typ  
doc  
txt  
par  
pid  
st   
235  /--Express `dist` in terms of `edist`-/
236  lemma dist_edist (x y : α) : dist x y = (edist x y).to_real :=
id                               └──┘     └───┘   └─────┘
src                               └──┘       └───┘     └─────┘
typ                              └──┘     └───┘   └─────┘
doc                                                     └─────┘
237  by rw [edist_dist, ennreal.to_real_of_real (dist_nonneg)]
id          └────────┘  └─────────────────────┘  └─────────┘
src     └──┘└────────┘└┘└─────────────────────┘ └─────────┘└──
typ     └──┘└────────┘└┘└─────────────────────┘ └─────────┘└──
doc     └──┘          └┘                                   └──
txt     └──┘          └┘                                   └──
par     └──┘          └┘                                   └──
pid       └┘          └┘                                   └┘
st     └─────────────┘└─────────────────────────────────────┘
238  
src  
typ  
doc  
txt  
par  
pid  
st   
239  namespace metric
240  
241  /- instantiate metric space as a topology -/
242  variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
id                                           └─┘
src                                          └─┘
typ                                          └─┘
243  
244  /-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
245  def ball (x : α) (ε : ℝ) : set α := {y | dist y x < ε}
id                            └─┘        └──┘    
src                            └─┘          └──┘     
typ                           └─┘        └──┘    
246  
247  @[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := iff.rfl
id                                └──┘    └──┘        └─────┘
src                                └──┘      └──┘           └─────┘
typ                               └──┘    └──┘        └─────┘
doc    └──┘                         └──┘
248  
249  theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw dist_comm; refl
id                         └──┘    └──┘              └───────┘
src                         └──┘      └──┘              └─┘└───────┘  └────
typ                        └──┘    └──┘           └─┘└───────┘  └────
doc                          └──┘                          └─┘           └────
txt                                                        └─┘           └────
par                                                        └─┘           └────
pid                                                                         
st                                                        └───────────────────
250  
src  
typ  
doc  
txt  
par  
pid  
st   
251  /-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/
252  def closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}
id                                       └──┘    
src                                        └──┘     
typ                                      └──┘    
253  
254  @[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl
id                                       └─────────┘    └──┘        └─────┘
src                                       └─────────┘      └──┘           └─────┘
typ                                      └─────────┘    └──┘        └─────┘
doc    └──┘                                └─────────┘
255  
256  theorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=
id                                     └──┘    └─────────┘  
src                                    └──┘      └─────────┘
typ                                    └──┘    └─────────┘  
doc                                    └──┘       └─────────┘
257  assume y, by simp; intros h; apply le_of_lt h
id                                     └──────┘ 
src               └──┘  └──────┘  └────┘└──────┘ 
typ              └──┘  └──────┘  └────┘└──────┘
doc               └──┘  └──────┘  └────┘         
txt               └──┘  └──────┘  └────┘         
par               └──┘  └──────┘  └────┘         
pid                           └┘                
st               └─────────────────────────────────
258  
src  
typ  
doc  
txt  
par  
pid  
st   
259  theorem pos_of_mem_ball (hy : y ∈ ball x ε) : ε > 0 :=
id                                   └──┘       
src                                   └──┘          
typ                                  └──┘       
doc                                    └──┘
260  lt_of_le_of_lt dist_nonneg hy
id   └────────────┘ └─────────┘ └┘
src  └────────────┘ └─────────┘
typ  └────────────┘ └─────────┘ └┘
261  
262  theorem mem_ball_self (h : ε > 0) : x ∈ ball x ε :=
id                                       └──┘  
src                                        └──┘
typ                                      └──┘  
doc                                          └──┘
263  show dist x x < ε, by rw dist_self; assumption
id        └──┘            └───────┘
src       └──┘            └─┘└───────┘  └──────────
typ       └──┘         └─┘└───────┘  └──────────
doc                        └─┘           └──────────
txt                        └─┘           └──────────
par                        └─┘           └──────────
pid                                               
st                        └─────────────────────────
264  
src  
typ  
doc  
txt  
par  
pid  
st   
265  theorem mem_closed_ball_self (h : ε ≥ 0) : x ∈ closed_ball x ε :=
id                                              └─────────┘  
src                                               └─────────┘
typ                                             └─────────┘  
doc                                                 └─────────┘
266  show dist x x ≤ ε, by rw dist_self; assumption
id        └──┘            └───────┘
src       └──┘            └─┘└───────┘  └──────────
typ       └──┘         └─┘└───────┘  └──────────
doc                        └─┘           └──────────
txt                        └─┘           └──────────
par                        └─┘           └──────────
pid                                               
st                        └─────────────────────────
267  
src  
typ  
doc  
txt  
par  
pid  
st   
268  theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=
id                             └──┘      └──┘  
src                             └──┘         └──┘
typ                            └──┘      └──┘  
doc                              └──┘           └──┘
269  by simp [dist_comm]
id            └───────┘
src     └────┘└───────┘└─
typ     └────┘└───────┘└─
doc     └────┘         └─
txt     └────┘         └─
par     └────┘         └─
pid                  
st     └─────────────────
270  
src  
typ  
doc  
txt  
par  
pid  
st   
271  theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ :=
id                                 └┘  └┘    └──┘  └┘  └──┘  └┘
src                                          └──┘       └──┘
typ                                └┘  └┘    └──┘  └┘  └──┘  └┘
doc                                           └──┘        └──┘
272  λ y (yx : _ < ε₁), lt_of_lt_of_le yx h
id               └┘   └────────────┘ └┘ 
src                    └────────────┘
typ              └┘   └────────────┘ └┘ 
273  
274  theorem closed_ball_subset_closed_ball {α : Type u} [metric_space α] {ε₁ ε₂ : ℝ} {x : α} (h : ε₁ ≤ ε₂) :
id                                                        └──────────┘                          └┘  └┘
src                                                       └──────────┘                               
typ                                                       └──────────┘                          └┘  └┘
doc                                                       └──────────┘
275    closed_ball x ε₁ ⊆ closed_ball x ε₂ :=
id     └─────────┘  └┘  └─────────┘  └┘
src    └─────────┘       └─────────┘
typ    └─────────┘  └┘  └─────────┘  └┘
doc    └─────────┘        └─────────┘
276  λ y (yx : _ ≤ ε₁), le_trans yx h
id               └┘   └──────┘ └┘ 
src                    └──────┘
typ              └┘   └──────┘ └┘ 
277  
278  theorem ball_disjoint (h : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ :=
id                              └┘  └┘  └──┘      └──┘  └┘  └──┘  └┘  
src                                     └──┘        └──┘       └──┘       
typ                             └┘  └┘  └──┘      └──┘  └┘  └──┘  └┘  
doc                                                   └──┘        └──┘
279  eq_empty_iff_forall_not_mem.2 $ λ z ⟨h₁, h₂⟩,
id   └─────────────────────────┘       └┘  └┘
src  └─────────────────────────┘
typ  └─────────────────────────┘       └┘  └┘
280  not_lt_of_le (dist_triangle_left x y z)
id   └──────────┘  └────────────────┘   
src  └──────────┘  └────────────────┘
typ  └──────────┘  └────────────────┘   
281    (lt_of_lt_of_le (add_lt_add h₁ h₂) h)
id      └────────────┘  └────────┘        
src     └────────────┘  └────────┘
typ     └────────────┘  └────────┘        
282  
283  theorem ball_disjoint_same (h : ε ≤ dist x y / 2) : ball x ε ∩ ball y ε = ∅ :=
id                                     └──┘         └──┘    └──┘    
src                                     └──┘           └──┘      └──┘      
typ                                    └──┘         └──┘    └──┘    
doc                                                      └──┘       └──┘
284  ball_disjoint $ by rwa [← two_mul, ← le_div_iff' two_pos]
id   └───────────┘             └─────┘    └─────────┘ └─────┘
src  └───────────┘      └─────┘└─────┘└──┘└─────────┘└─────┘└─
typ  └───────────┘      └─────┘└─────┘└──┘└─────────┘└─────┘└─
doc                     └─────┘       └──┘                  └─
txt                     └─────┘       └──┘                  └─
par                     └─────┘       └──┘                  └─
pid                        └──┘       └──┘                  
st                     └─────────────┘└─────────────────────┘
285  
src  
typ  
doc  
txt  
par  
pid  
st   
286  theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ :=
id                            └──┘    └┘  └┘    └──┘  └┘  └──┘  └┘
src                           └──┘                └──┘       └──┘
typ                           └──┘    └┘  └┘    └──┘  └┘  └──┘  └┘
doc                                                 └──┘        └──┘
287  λ z zx, by rw ← add_sub_cancel'_right ε₁ ε₂; exact
id      └┘          └───────────────────┘ └┘ └┘
src             └───┘└───────────────────┘      └────┘
typ     └┘     └───┘└───────────────────┘└┘└┘  └────┘
doc             └───┘                           └────┘
txt             └───┘                           └────┘
par             └───┘                           └────┘
pid               └─┘                                
st             └────────────────────────────────────────
288  lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)
id   └────────────┘  └───────────┘      └────────────────────┘ └┘ 
src  └────────────┘ └───────────┘   └┘ └────────────────────┘   └─
typ  └────────────┘ └───────────┘└┘ └────────────────────┘└┘└─
doc                                 └┘                          └─
txt                                 └┘                          └─
par                                 └┘                          └─
pid                                 └┘                          
st   ───────────────────────────────────────────────────────────────────
289  
src  
typ  
doc  
txt  
par  
pid  
st   
290  theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=
id                                       └──┘           └──┘         └──┘  
src                                       └──┘             └──┘           └──┘
typ                                      └──┘           └──┘         └──┘  
doc                                        └──┘              └──┘             └──┘
291  ball_subset $ by rw sub_self_div_two; exact le_of_lt h
id   └─────────┘         └──────────────┘        └──────┘ 
src  └─────────┘      └─┘└──────────────┘  └────┘└──────┘ 
typ  └─────────┘      └─┘└──────────────┘  └────┘└──────┘
doc                   └─┘                  └────┘         
txt                   └─┘                  └────┘         
par                   └─┘                  └────┘         
pid                                                     
st                   └──────────────────────────────────────
292  
src  
typ  
doc  
txt  
par  
pid  
st   
293  theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
id                                          └──┘       └┘     └──┘  └┘  └──┘  
src                                          └──┘                └──┘       └──┘
typ                                         └──┘       └┘     └──┘  └┘  └──┘  
doc                                           └──┘                  └──┘        └──┘
294  ⟨_, sub_pos.2 h, ball_subset $ by rw sub_sub_self⟩
id       └─────┘    └─────────┘         └──────────┘
src      └─────┘     └─────────┘      └─┘└──────────┘
typ      └─────┘    └─────────┘      └─┘└──────────┘
doc                                    └─┘
txt                                    └─┘
par                                    └─┘
pid                                      
st                                    └──────────────┘
295  
296  theorem ball_eq_empty_iff_nonpos : ε ≤ 0 ↔ ball x ε = ∅ :=
id                                           └──┘    
src                                           └──┘      
typ                                          └──┘    
doc                                             └──┘
297  (eq_empty_iff_forall_not_mem.trans
id    └─────────────────────────┘└────┘
src   └─────────────────────────┘└────┘
typ   └─────────────────────────┘└────┘
298  ⟨λ h, le_of_not_gt $ λ ε0, h _ $ mem_ball_self ε0,
id        └──────────┘     └┘       └───────────┘ └┘
src        └──────────┘               └───────────┘
typ       └──────────┘     └┘       └───────────┘ └┘
299   λ ε0 y h, not_lt_of_le ε0 $ pos_of_mem_ball h⟩).symm
id      └┘    └──────────┘ └┘   └─────────────┘   └──┘
src             └──────────┘      └─────────────┘    └──┘
typ     └┘    └──────────┘ └┘   └─────────────┘   └──┘
300  
301  theorem uniformity_dist : 𝓤 α = (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}) :=
id                                     └───────┘      └──┘      
src                                      └───────┘        └──┘       
typ                                    └───────┘      └──┘      
doc                                       └───────┘
302  metric_space.uniformity_dist _
id   └──────────────────────────┘
src  └──────────────────────────┘
typ  └──────────────────────────┘
303  
304  theorem uniformity_dist' : 𝓤 α = (⨅ε:{ε:ℝ // ε>0}, principal {p:α×α | dist p.1 p.2 < ε.val}) :=
id                                             └───────┘      └──┘      └──┘
src                                              └───────┘        └──┘         └──┘
typ                                            └───────┘      └──┘      └──┘
doc                                                  └───────┘
305  by simp [infi_subtype]; exact uniformity_dist
id            └──────────┘         └─────────────┘
src     └────┘└──────────┘  └────┘└─────────────┘
typ     └────┘└──────────┘  └────┘└─────────────┘
doc     └────┘              └────┘               
txt     └────┘              └────┘               
par     └────┘              └────┘               
pid                                           
st     └───────────────────────────────────────────
306  
src  
typ  
doc  
txt  
par  
pid  
st   
307  theorem mem_uniformity_dist {s : set (α×α)} :
id                                    └─┘  
src                                   └─┘   
typ                                   └─┘  
308    s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) :=
id                       └──┘            
src                          └──┘                
typ                      └──┘            
doc        
309  begin
st   └─────
310    rw [uniformity_dist', mem_infi],
id         └──────────────┘  └──────┘
src    └──┘└──────────────┘└┘└──────┘
typ    └──┘└──────────────┘└┘└──────┘
doc    └──┘                └┘        
txt    └──┘                └┘        
par    └──┘                └┘        
pid      └┘                └┘        
st   ─────────────────────┘└────────┘└──
311    simp [subset_def],
id           └────────┘
src    └────┘└────────┘
typ    └────┘└────────┘
doc    └────┘          
txt    └────┘          
par    └────┘          
pid                  
st   ──────────────────┘└─
312    exact assume ⟨r, hr⟩ ⟨p, hp⟩, ⟨⟨min r p, lt_min hr hp⟩, by simp [lt_min_iff, (≥)] {contextual := tt}⟩,
id                     └┘     └┘     └─┘      └────┘                  └────────┘                     └┘
src    └────┘      └┘ └┘  └─┘ └┘  └─┘  └─┘  └┘└────┘    └─┘  └────┘└────────┘└┘└──┘ └────────────┘└┘
typ    └────┘      └┘└┘└┘└─┘└┘└┘└─┘  └─┘  └┘└────┘    └─┘  └────┘└────────┘└┘└──┘ └────────────┘└┘
doc    └────┘      └┘ └┘  └─┘ └┘  └─┘       └┘          └─┘  └────┘          └┘ └──┘ └────────────┘  
txt    └────┘      └┘ └┘  └─┘ └┘  └─┘       └┘          └─┘  └────┘          └┘ └──┘ └────────────┘  
par    └────┘      └┘ └┘  └─┘ └┘  └─┘       └┘          └─┘  └────┘          └┘ └──┘ └────────────┘  
pid               └┘ └┘  └─┘ └┘  └─┘       └┘          └─┘  └─────┘          └┘ └──┘ └────────────┘  └┘
st   ───────────────────────────────────────────────────────────┘└────────────────────────────────────────┘└─
313    exact ⟨⟨1, zero_lt_one⟩⟩
id                └─────────┘
src    └────┘  └─┘└─────────┘└─┘
typ    └────┘  └─┘└─────────┘└─┘
doc    └────┘  └─┘           └─┘
txt    └────┘  └─┘           └─┘
par    └────┘  └─┘           └─┘
pid           └─┘           └┘
st   ──────────────────────────┘
314  end
st   └─┘
315  
316  theorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) :
id                                             
src                                           
typ                                            
317    {p:α×α | dist p.1 p.2 < ε} ∈ 𝓤 α :=
id          └──┘          
src           └──┘            
typ         └──┘          
doc                                 
318  mem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩
id   └─────────────────┘     └┘       └┘
src  └─────────────────┘                 └┘
typ  └─────────────────┘     └┘       └┘
319  
320  theorem uniform_continuous_iff [metric_space β] {f : α → β} :
id                                   └──────────┘           
src                                  └──────────┘
typ                                  └──────────┘           
doc                                  └──────────┘
321    uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,
id     └────────────────┘                
src    └────────────────┘                  
typ    └────────────────┘                
322      ∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε :=
id                └──┘       └──┘          
src                └──┘          └──┘             
typ               └──┘       └──┘          
323  uniform_continuous_def.trans
id   └────────────────────┘└────┘
src  └────────────────────┘└────┘
typ  └────────────────────┘└────┘
324  ⟨λ H ε ε0, mem_uniformity_dist.1 $ H _ $ dist_mem_uniformity ε0,
id        └┘  └─────────────────┘         └─────────────────┘ └┘
src             └─────────────────┘          └─────────────────┘
typ       └┘  └─────────────────┘         └─────────────────┘ └┘
325   λ H r ru,
id        └┘
typ       └┘
326    let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru, ⟨δ, δ0, hδ⟩ := H _ ε0 in
id     └─┘     └┘  └┘     └─────────────────┘  └┘     └┘  └┘     
src                       └─────────────────┘
typ    └─┘     └┘  └┘     └─────────────────┘  └┘     └┘  └┘     
327    mem_uniformity_dist.2 ⟨δ, δ0, λ a b h, hε (hδ h)⟩⟩
id     └─────────────────┘                       
src    └─────────────────┘
typ    └─────────────────┘                       
328  
329  theorem uniform_embedding_iff [metric_space β] {f : α → β} :
id                                  └──────────┘           
src                                 └──────────┘
typ                                 └──────────┘           
doc                                 └──────────┘
330    uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
id     └───────────────┘   └────────────────┘   └────────────────┘  
src    └───────────────┘    └────────────────┘    └────────────────┘   
typ    └───────────────┘   └────────────────┘   └────────────────┘  
331      ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
id                                 └──┘             └──┘    
src                                   └──┘                  └──┘     
typ                                └──┘             └──┘    
332  uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
id   └────────────────────┘└────┘   └───────┘ └─────┘   └───────┘ └─────┘
src  └────────────────────┘└────┘   └───────┘ └─────┘   └───────┘ └─────┘
typ  └────────────────────┘└────┘   └───────┘ └─────┘   └───────┘ └─────┘
333  ⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0),
id        └┘  └─┘     └┘  └┘         └─────────────────┘ └┘
src                                     └─────────────────┘
typ       └┘  └─┘     └┘  └┘         └─────────────────┘ └┘
334                 ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu in
id                     └┘  └┘     └─────────────────┘
src                                └─────────────────┘
typ                    └┘  └┘     └─────────────────┘
335    ⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,
id                              
typ                             
336   λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in
id        └┘  └─┘     └┘  └┘     └─────────────────┘  └┘      └┘  └┘     
src                                └─────────────────┘
typ       └┘  └─┘     └┘  └┘     └─────────────────┘  └┘      └┘  └┘     
337    ⟨_, dist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩
id         └─────────────────┘                  
src        └─────────────────┘
typ        └─────────────────┘                  
338  
339  /-- A map between metric spaces is a uniform embedding if and only if the distance between `f x`
340  and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
341  theorem uniform_embedding_iff' [metric_space β] {f : α → β} :
id                                   └──────────┘           
src                                  └──────────┘
typ                                  └──────────┘           
doc                                  └──────────┘
342    uniform_embedding f ↔
id     └───────────────┘  
src    └───────────────┘   
typ    └───────────────┘  
343    (∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧
id                                └──┘       └──┘            
src                                  └──┘          └──┘                 
typ                               └──┘       └──┘            
344    (∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ) :=
id                                └──┘             └──┘    
src                                  └──┘                  └──┘     
typ                               └──┘             └──┘    
345  begin
st   └─────
346    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
347    { assume h,
src      └──────┘
typ      └──────┘
doc      └──────┘
txt      └──────┘
par      └──────┘
pid      └──────┘
st   ───┘└──────┘└─
348      exact ⟨uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1,
id              └────────────────────┘
src      └────┘ └────────────────────┘└─┘                      └─┘ └──────
typ      └────┘ └────────────────────┘└─┘                      └─┘ └──────
doc      └────┘                       └─┘                      └─┘ └──────
txt      └────┘                       └─┘                      └─┘ └──────
par      └────┘                       └─┘                      └─┘ └──────
pid                                  └─┘                      └─┘ └──────
st   ─────────────────────────────────────────────────────────────────────
349            (uniform_embedding_iff.1 h).2.2⟩ },
id              └───────────────────┘   
src  ─────────┘ └───────────────────┘└─┘ └─────┘
typ  ─────────┘ └───────────────────┘└─┘└─────┘
doc  ─────────┘                      └─┘ └─────┘
txt  ─────────┘                      └─┘ └─────┘
par  ─────────┘                      └─┘ └─────┘
pid  ─────────┘                      └─┘ └────┘
st   ──────────────────────────────────────────┘└┘
350    { rintros ⟨h₁, h₂⟩,
src      └──────────────┘
typ      └──────────────┘
doc      └──────────────┘
txt      └──────────────┘
par      └──────────────┘
pid             └───────┘
st   ───────────────────┘└─
351      refine uniform_embedding_iff.2 ⟨_, uniform_continuous_iff.2 h₁, h₂⟩,
id              └───────────────────┘       └────────────────────┘   └┘  └┘
src      └─────┘└───────────────────┘└─┘ └─┘└────────────────────┘└─┘  └┘  
typ      └─────┘└───────────────────┘└─┘ └─┘└────────────────────┘└─┘└┘└┘└┘
doc      └─────┘                     └─┘ └─┘                      └─┘  └┘  
txt      └─────┘                     └─┘ └─┘                      └─┘  └┘  
par      └─────┘                     └─┘ └─┘                      └─┘  └┘  
pid                                 └─┘ └─┘                      └─┘  └┘  
st   ──────────────────────────────────────────────────────────────────────┘└─
352      assume x y hxy,
src      └────────────┘
typ      └────────────┘
doc      └────────────┘
txt      └────────────┘
par      └────────────┘
pid      └────────────┘
st   ─────────────────┘└─
353      have : dist x y ≤ 0,
id              └──┘   
src      └─────┘└──┘  └┘
typ      └─────┘└──┘└┘
doc      └─────┘       └┘
txt      └─────┘       └┘
par      └─────┘       └┘
pid      └───┘└┘       
st   ──────────────────────┘└─
354      { refine le_of_forall_lt' (λδ δpos, _),
id                └──────────────┘
src        └─────┘└──────────────┘  └────────┘
typ        └─────┘└──────────────┘  └────────┘
doc        └─────┘                  └────────┘
txt        └─────┘                  └────────┘
par        └─────┘                  └────────┘
pid                                └────────┘
st   ─────┘└──────────────────────────────────┘└─
355        rcases h₂ δ δpos with ⟨ε, εpos, hε⟩,
id                └┘  └──┘
src        └─────┘       └─────────────────┘
typ        └─────┘└┘└──┘└─────────────────┘
doc        └─────┘       └─────────────────┘
txt        └─────┘       └─────────────────┘
par        └─────┘       └─────────────────┘
pid                     └─────────────────┘
st   ────────────────────────────────────────┘└─
356        have : dist (f x) (f y) < ε, by simpa [hxy],
id                └──┘                       └─┘
src        └─────┘└──┘   └┘   └┘      └─────┘   
typ        └─────┘└──┘  └┘ └┘     └─────┘└─┘
doc        └─────┘       └┘   └┘       └─────┘   
txt        └─────┘       └┘   └┘       └─────┘   
par        └─────┘       └┘   └┘       └─────┘   
pid        └───┘└┘       └┘   └┘               
st   ────────────────────────────────┘                └─
357        exact hε this },
id               └┘ └──┘
src        └────┘      
typ        └────┘└┘└──┘
doc        └────┘      
txt        └────┘      
par        └────┘      
pid                   
st   ───────────────────┘└┘
358      simpa using this }
id                   └──┘
src      └──────────┘    
typ      └──────────┘└──┘
doc      └──────────┘    
txt      └──────────┘    
par      └──────────┘    
pid           └────┘    
st   ────────────────────┘└─
359  end
st   ──┘
360  
361  theorem totally_bounded_iff {s : set α} :
id                                    └─┘ 
src                                   └─┘
typ                                   └─┘ 
362    totally_bounded s ↔ ∀ ε > 0, ∃t : set α, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
id     └─────────────┘               └─┘  └────┘       └──┘  
src    └─────────────┘                 └─┘   └────┘           └──┘
typ    └─────────────┘               └─┘  └────┘       └──┘  
doc    └─────────────┘                          └────┘             └──┘
363  ⟨λ H ε ε0, H _ (dist_mem_uniformity ε0),
id        └┘      └─────────────────┘ └┘
src                  └─────────────────┘
typ       └┘      └─────────────────┘ └┘
364   λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
id        └┘  └─┘    └┘  └┘     └─────────────────┘  └┘
src                                └─────────────────┘
typ       └┘  └─┘    └┘  └┘     └─────────────────┘  └┘
365                 ⟨t, ft, h⟩ := H ε ε0 in
id                     └┘       
typ                    └┘       
366    ⟨t, ft, subset.trans h $ Union_subset_Union $ λ y, Union_subset_Union $ λ yt z, hε⟩⟩
id             └──────────┘     └────────────────┘       └────────────────┘     └┘ 
src            └──────────┘     └────────────────┘        └────────────────┘
typ            └──────────┘     └────────────────┘       └────────────────┘     └┘ 
367  
368  /-- A metric space space is totally bounded if one can reconstruct up to any ε>0 any element of the
369  space from finitely many data. -/
370  lemma totally_bounded_of_finite_discretization {α : Type u} [metric_space α] {s : set α}
id                                                                └──────────┘        └─┘ 
src                                                               └──────────┘         └─┘
typ                                                               └──────────┘        └─┘ 
doc                                                               └──────────┘
371    (H : ∀ε > (0 : ℝ), ∃ (β : Type u) [fintype β] (F : s → β),
id                            └──┘     └─────┘           
src                                     └─────┘               
typ                           └──┘     └─────┘           
doc                                       └─────┘
372      ∀x y, F x = F y → dist (x:α) y < ε) :
id                  └──┘       
src                       └──┘         
typ                 └──┘       
373    totally_bounded s :=
id     └─────────────┘ 
src    └─────────────┘
typ    └─────────────┘ 
doc    └─────────────┘
374  begin
st   └─────
375    cases s.eq_empty_or_nonempty with hs hs,
id           └────────────────────┘
src    └────┘└────────────────────┘└─────────┘
typ    └────┘└────────────────────┘└─────────┘
doc    └────┘                      └─────────┘
txt    └────┘                      └─────────┘
par    └────┘                      └─────────┘
pid                               └─────────┘
st   ────────────────────────────────────────┘└─
376    { rw hs, exact totally_bounded_empty },
id          └┘        └───────────────────┘
src      └─┘    └────┘└───────────────────┘
typ      └─┘└┘  └────┘└───────────────────┘
doc      └─┘    └────┘                     
txt      └─┘    └────┘                     
par      └─┘    └────┘                     
pid                                      
st   ───┘└───┘└────────────────────────────┘└┘
377    rcases hs with ⟨x0, hx0⟩,
id            └┘
src    └─────┘  └─────────────┘
typ    └─────┘└┘└─────────────┘
doc    └─────┘  └─────────────┘
txt    └─────┘  └─────────────┘
par    └─────┘  └─────────────┘
pid            └─────────────┘
st   ─────────────────────────┘└─
378    haveI : inhabited s := ⟨⟨x0, hx0⟩⟩,
id             └───────┘       └┘  └─┘
src    └──────┘└───────┘ └──┘    └┘   └┘
typ    └──────┘└───────┘└──┘  └┘└┘└─┘└┘
doc    └──────┘          └──┘    └┘   └┘
txt    └──────┘          └──┘    └┘   └┘
par    └──────┘          └──┘    └┘   └┘
pid         └┘          └──┘    └┘   └┘
st   ───────────────────────────────────┘└─
379    refine totally_bounded_iff.2 (λ ε ε0, _),
id            └─────────────────┘
src    └─────┘└─────────────────┘└─┘  └───────┘
typ    └─────┘└─────────────────┘└─┘  └───────┘
doc    └─────┘                   └─┘  └───────┘
txt    └─────┘                   └─┘  └───────┘
par    └─────┘                   └─┘  └───────┘
pid                             └─┘  └───────┘
st   ─────────────────────────────────────────┘└─
380    rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
id              └┘
src    └─────┘    └──────────────────┘
typ    └─────┘└┘└──────────────────┘
doc    └─────┘    └──────────────────┘
txt    └─────┘    └──────────────────┘
par    └─────┘    └──────────────────┘
pid              └──────────────────┘
st   ──────────────────────────────────┘└─
381    let Finv := function.inv_fun F,
id                 └──────────────┘ 
src    └──────────┘└──────────────┘
typ    └──────────┘└──────────────┘
doc    └──────────┘└──────────────┘
txt    └──────────┘                
par    └──────────┘                
pid    └──────┘└─┘                
st   ───────────────────────────────┘└─
382    refine ⟨range (subtype.val ∘ Finv), finite_range _, λ x xs, _⟩,
id             └───┘  └─────────┘  └──┘   └──────────┘
src    └─────┘ └───┘ └─────────┘    └─┘└──────────┘└──┘ └───────┘
typ    └─────┘ └───┘ └─────────┘└──┘└─┘└──────────┘└──┘ └───────┘
doc    └─────┘ └───┘                 └─┘            └──┘ └───────┘
txt    └─────┘                       └─┘            └──┘ └───────┘
par    └─────┘                       └─┘            └──┘ └───────┘
pid                                 └─┘            └──┘ └───────┘
st   ───────────────────────────────────────────────────────────────┘└─
383    let x' := Finv (F ⟨x, xs⟩),
id               └──┘      └┘
src    └────────┘        └┘  └┘
typ    └────────┘└──┘  └┘└┘└┘
doc    └────────┘        └┘  └┘
txt    └────────┘        └┘  └┘
par    └────────┘        └┘  └┘
pid    └────┘└─┘        └┘  └┘
st   ───────────────────────────┘└─
384    have : F x' = F ⟨x, xs⟩ := function.inv_fun_eq ⟨⟨x, xs⟩, rfl⟩,
id              └┘      └┘     └─────────────────┘     └┘   └─┘
src    └─────┘      └┘  └───┘└─────────────────┘   └┘  └─┘└─┘
typ    └─────┘ └┘ └┘└┘└───┘└─────────────────┘  └┘└┘└─┘└─┘
doc    └─────┘       └┘  └───┘                      └┘  └─┘   
txt    └─────┘       └┘  └───┘                      └┘  └─┘   
par    └─────┘       └┘  └───┘                      └┘  └─┘   
pid    └───┘└┘       └┘  └──┘                      └┘  └─┘   
st   ──────────────────────────────────────────────────────────────┘└─
385    simp only [set.mem_Union, set.mem_range],
id                └───────────┘  └───────────┘
src    └─────────┘└───────────┘└┘└───────────┘
typ    └─────────┘└───────────┘└┘└───────────┘
doc    └─────────┘             └┘             
txt    └─────────┘             └┘             
par    └─────────┘             └┘             
pid        └──┘└┘             └┘             
st   ─────────────────────────────────────────┘└─
386    exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩
id                    └┘   └─┘   └┘     └───────┘
src    └────┘ └─┘    └┘  └─┘└─┘└─┘  └───┘└───────┘└┘
typ    └────┘ └─┘  └┘└┘└─┘└─┘└─┘└┘└───┘└───────┘└┘
doc    └────┘ └─┘    └┘  └─┘   └─┘  └───┘         └┘
txt    └────┘ └─┘    └┘  └─┘   └─┘  └───┘         └┘
par    └────┘ └─┘    └┘  └─┘   └─┘  └───┘         └┘
pid          └─┘    └┘  └─┘   └─┘  └───┘         
st   ───────────────────────────────────────────────┘
387  end
st   └─┘
388  
389  protected lemma cauchy_iff {f : filter α} :
id                                   └────┘ 
src                                  └────┘
typ                                  └────┘ 
390    cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, dist x y < ε :=
id     └────┘                            └──┘    
src    └────┘                                   └──┘     
typ    └────┘                            └──┘    
doc    └────┘
391  cauchy_iff.trans $ and_congr iff.rfl
id   └────────┘└────┘   └───────┘ └─────┘
src  └────────┘└────┘   └───────┘ └─────┘
typ  └────────┘└────┘   └───────┘ └─────┘
392  ⟨λ H ε ε0, let ⟨t, tf, ts⟩ := H _ (dist_mem_uniformity ε0) in
id        └┘  └─┘    └┘  └┘         └─────────────────┘ └┘
src                                     └─────────────────┘
typ       └┘  └─┘    └┘  └┘         └─────────────────┘ └┘
393     ⟨t, tf, λ x y xt yt, @ts (x, y) ⟨xt, yt⟩⟩,
id                  └┘ └┘           └┘  └┘
src                              
typ                 └┘ └┘           └┘  └┘
394   λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
id        └┘  └─┘    └┘  └┘     └─────────────────┘  └┘
src                                └─────────────────┘
typ       └┘  └─┘    └┘  └┘     └─────────────────┘  └┘
395                 ⟨t, tf, h⟩ := H ε ε0 in
id                     └┘       
typ                    └┘       
396     ⟨t, tf, λ ⟨x, y⟩ ⟨hx, hy⟩, hε (h x y hx hy)⟩⟩
id                    └┘  └┘
typ                   └┘  └┘
397  
398  theorem nhds_eq : 𝓝 x = (⨅ε:{ε:ℝ // ε>0}, principal (ball x ε.val)) :=
id                                    └───────┘  └──┘  └──┘
src                                     └───────┘  └──┘    └──┘
typ                                   └───────┘  └──┘  └──┘
doc                                         └───────┘  └──┘
399  begin
st   └─────
400    rw [nhds_eq_uniformity, uniformity_dist', lift'_infi],
id         └────────────────┘  └──────────────┘  └────────┘
src    └──┘└────────────────┘└┘└──────────────┘└┘└────────┘
typ    └──┘└────────────────┘└┘└──────────────┘└┘└────────┘
doc    └──┘                  └┘                └┘          
txt    └──┘                  └┘                └┘          
par    └──┘                  └┘                └┘          
pid      └┘                  └┘                └┘          
st   ───────────────────────┘└────────────────┘└──────────┘└──
401    { apply congr_arg, funext ε,
id             └───────┘
src      └────┘└───────┘  └──────┘
typ      └────┘└───────┘  └──────┘
doc      └────┘           └──────┘
txt      └────┘           └──────┘
par      └────┘           └──────┘
pid                            └┘
st   ───┘└─────────────┘└────────┘└─
402      rw [lift'_principal],
id           └─────────────┘
src      └──┘└─────────────┘
typ      └──┘└─────────────┘
doc      └──┘               
txt      └──┘               
par      └──┘               
pid        └┘               
st   ──────────────────────┘└──
403      { simp [ball, dist_comm] },
id               └──┘  └───────┘
src        └────┘└──┘└┘└───────┘└┘
typ        └────┘└──┘└┘└───────┘└┘
doc        └────┘└──┘└┘         └┘
txt        └────┘    └┘         └┘
par        └────┘    └┘         └┘
pid                └┘         
st   ─────┘└─────────────────────┘└┘
404      { exact monotone_preimage } },
id               └───────────────┘
src        └────┘└───────────────┘
typ        └────┘└───────────────┘
doc        └────┘                 
txt        └────┘                 
par        └────┘                 
pid                              
st   ─────────────────────────────┘└──┘
405    { exact ⟨⟨1, zero_lt_one⟩⟩ },
id                  └─────────┘
src      └────┘  └─┘└─────────┘└─┘
typ      └────┘  └─┘└─────────┘└─┘
doc      └────┘  └─┘           └─┘
txt      └────┘  └─┘           └─┘
par      └────┘  └─┘           └─┘
pid             └─┘           └┘
st   ───┘└───────────────────────┘└┘
406    { intros, refl }
src      └────┘  └───┘
typ      └────┘  └───┘
doc      └────┘  └───┘
txt      └────┘  └───┘
par      └────┘  └───┘
pid                  
st   ─────────┘└─────┘└─
407  end
st   ──┘
408  
409  theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ε>0, ball x ε ⊆ s :=
id                                  └──┘    
src                                    └──┘     
typ                                 └──┘    
doc                                        └──┘
410  begin
st   └─────
411    rw [nhds_eq, mem_infi],
id         └─────┘  └──────┘
src    └──┘└─────┘└┘└──────┘
typ    └──┘└─────┘└┘└──────┘
doc    └──┘       └┘        
txt    └──┘       └┘        
par    └──┘       └┘        
pid      └┘       └┘        
st   ────────────┘└────────┘└──
412    { simp },
src      └───┘
typ      └───┘
doc      └───┘
txt      └───┘
par      └───┘
pid          
st   ───┘└───┘└┘
413    { intros y z, cases y with y hy, cases z with z hz,
id                                           
src      └────────┘  └────┘ └────────┘  └────┘ └────────┘
typ      └────────┘  └────┘└────────┘  └────┘└────────┘
doc      └────────┘  └────┘ └────────┘  └────┘ └────────┘
txt      └────────┘  └────┘ └────────┘  └────┘ └────────┘
par      └────────┘  └────┘ └────────┘  └────┘ └────────┘
pid            └──┘        └────────┘        └────────┘
st   ───┘└────────┘└─────────────────┘└─────────────────┘└─
414      refine ⟨⟨min y z, lt_min hy hz⟩, _⟩,
id                └─┘    └────┘ └┘ └┘
src      └─────┘  └─┘  └┘└────┘    └───┘
typ      └─────┘  └─┘└┘└────┘└┘└┘└───┘
doc      └─────┘       └┘          └───┘
txt      └─────┘       └┘          └───┘
par      └─────┘       └┘          └───┘
pid                   └┘          └───┘
st   ──────────────────────────────────────┘└─
415      simp [ball_subset_ball, min_le_left, min_le_right, (≥)] },
id             └──────────────┘  └─────────┘  └──────────┘  
src      └────┘└──────────────┘└┘└─────────┘└┘└──────────┘└┘└──┘
typ      └────┘└──────────────┘└┘└─────────┘└┘└──────────┘└┘└──┘
doc      └────┘                └┘           └┘            └┘ └──┘
txt      └────┘                └┘           └┘            └┘ └──┘
par      └────┘                └┘           └┘            └┘ └──┘
pid                          └┘           └┘            └┘ └─┘
st   ───────────────────────────────────────────────────────────┘└┘
416    { exact ⟨⟨1, zero_lt_one⟩⟩ }
id                  └─────────┘
src      └────┘  └─┘└─────────┘└─┘
typ      └────┘  └─┘└─────────┘└─┘
doc      └────┘  └─┘           └─┘
txt      └────┘  └─┘           └─┘
par      └────┘  └─┘           └─┘
pid             └─┘           └┘
st   ────────────────────────────┘└─
417  end
st   ──┘
418  
419  theorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=
id                         └─────┘          └──┘    
src                        └─────┘              └──┘     
typ                        └─────┘          └──┘    
doc                        └─────┘                 └──┘
420  by simp [is_open_iff_nhds, mem_nhds_iff]
id            └──────────────┘  └──────────┘
src     └────┘└──────────────┘└┘└──────────┘└─
typ     └────┘└──────────────┘└┘└──────────┘└─
doc     └────┘                └┘            └─
txt     └────┘                └┘            └─
par     └────┘                └┘            └─
pid                         └┘            
st     └──────────────────────────────────────
421  
src  
typ  
doc  
txt  
par  
pid  
st   
422  theorem is_open_ball : is_open (ball x ε) :=
id                          └─────┘  └──┘  
src                         └─────┘  └──┘
typ                         └─────┘  └──┘  
doc                         └─────┘  └──┘
st                                               
423  is_open_iff.2 $ λ y, exists_ball_subset_ball
id   └─────────┘        └─────────────────────┘
src  └─────────┘         └─────────────────────┘
typ  └─────────┘        └─────────────────────┘
424  
425  theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x :=
id                                                    └──┘     
src                                                     └──┘      
typ                                                   └──┘     
doc                                                       └──┘       
426  mem_nhds_sets is_open_ball (mem_ball_self ε0)
id   └───────────┘ └──────────┘  └───────────┘ └┘
src  └───────────┘ └──────────┘  └───────────┘
typ  └───────────┘ └──────────┘  └───────────┘ └┘
427  
428  @[nolint] -- see Note [nolint_ge]
doc    └────┘
429  theorem mem_nhds_within_iff {t : set α} : s ∈ nhds_within x t ↔ ∃ε>0, ball x ε ∩ t ⊆ s :=
id                                    └─┘       └─────────┘       └──┘      
src                                   └─┘         └─────────┘          └──┘        
typ                                   └─┘       └─────────┘       └──┘      
doc                                                └─────────┘             └──┘
430  begin
st   └─────
431    rw [mem_nhds_within_iff_exists_mem_nhds_inter],
id         └───────────────────────────────────────┘
src    └──┘└───────────────────────────────────────┘
typ    └──┘└───────────────────────────────────────┘
doc    └──┘                                         
txt    └──┘                                         
par    └──┘                                         
pid      └┘                                         
st   ──────────────────────────────────────────────┘└──
432    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
433    { rintros ⟨u, hu, H⟩,
src      └────────────────┘
typ      └────────────────┘
doc      └────────────────┘
txt      └────────────────┘
par      └────────────────┘
pid             └─────────┘
st   ───┘└────────────────┘└─
434      rcases mem_nhds_iff.1 hu with ⟨ε, ε_pos, hε⟩,
id              └──────────┘   └┘
src      └─────┘└──────────┘└─┘  └──────────────────┘
typ      └─────┘└──────────┘└─┘└┘└──────────────────┘
doc      └─────┘            └─┘  └──────────────────┘
txt      └─────┘            └─┘  └──────────────────┘
par      └─────┘            └─┘  └──────────────────┘
pid                        └─┘  └──────────────────┘
st   ───────────────────────────────────────────────┘└─
435      exact ⟨ε, ε_pos, subset.trans (inter_subset_inter_left _ hε) H⟩ },
id                └───┘  └──────────┘  └─────────────────────┘   └┘  
src      └────┘  └┘     └┘└──────────┘ └─────────────────────┘└─┘  └┘ └┘
typ      └────┘ └┘└───┘└┘└──────────┘ └─────────────────────┘└─┘└┘└┘└┘
doc      └────┘  └┘     └┘                                    └─┘  └┘ └┘
txt      └────┘  └┘     └┘                                    └─┘  └┘ └┘
par      └────┘  └┘     └┘                                    └─┘  └┘ └┘
pid             └┘     └┘                                    └─┘  └┘ 
st   ───────────────────────────────────────────────────────────────────┘└┘
436    { rintros ⟨ε, ε_pos, H⟩,
src      └───────────────────┘
typ      └───────────────────┘
doc      └───────────────────┘
txt      └───────────────────┘
par      └───────────────────┘
pid             └────────────┘
st   ────────────────────────┘└─
437      exact ⟨ball x ε, ball_mem_nhds x ε_pos, H⟩ }
id              └──┘     └───────────┘  └───┘  
src      └────┘ └──┘  └┘└───────────┘      └┘ └┘
typ      └────┘ └──┘ └┘└───────────┘└───┘└┘└┘
doc      └────┘ └──┘  └┘                   └┘ └┘
txt      └────┘       └┘                   └┘ └┘
par      └────┘       └┘                   └┘ └┘
pid                  └┘                   └┘ 
st   ──────────────────────────────────────────────┘└─
438  end
st   ──┘
439  
440  @[nolint] -- see Note [nolint_ge]
doc    └────┘
441  theorem tendsto_nhds_within_nhds_within [metric_space β] {t : set β} {f : α → β} {a b} :
id                                            └──────────┘        └─┘           
src                                           └──────────┘         └─┘
typ                                           └──────────┘        └─┘           
doc                                           └──────────┘
442    tendsto f (nhds_within a s) (nhds_within b t) ↔
id     └─────┘   └─────────┘     └─────────┘    
src    └─────┘    └─────────┘       └─────────┘      
typ    └─────┘   └─────────┘     └─────────┘    
doc    └─────┘    └─────────┘       └─────────┘
443      ∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε :=
id                                 └──┘            └──┘       
src                                     └──┘                  └──┘         
typ                                └──┘            └──┘       
444  begin
st   └─────
445    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
446    { assume H ε ε_pos,
src      └──────────────┘
typ      └──────────────┘
doc      └──────────────┘
txt      └──────────────┘
par      └──────────────┘
pid      └──────────────┘
st   ───┘└──────────────┘└─
447      have : ball b ε ∩ t ∈ nhds_within b t,
id              └──┘        └─────────┘  
src      └─────┘└──┘   └─────────┘ 
typ      └─────┘└──┘  └─────────┘
doc      └─────┘└──┘     └─────────┘ 
txt      └─────┘                     
par      └─────┘                     
pid      └───┘└┘                     
st   ────────────────────────────────────────┘
448        by { rw mem_nhds_within_iff, exact ⟨ε, ε_pos, subset.refl _⟩ },
id                 └─────────────────┘           └───┘  └─────────┘
src             └─┘└─────────────────┘  └────┘  └┘     └┘└─────────┘└──┘
typ             └─┘└─────────────────┘  └────┘ └┘└───┘└┘└─────────┘└──┘
doc             └─┘                     └────┘  └┘     └┘           └──┘
txt             └─┘                     └────┘  └┘     └┘           └──┘
par             └─┘                     └────┘  └┘     └┘           └──┘
pid                                           └┘     └┘           └─┘
st            └─────────────────────┘└────────────────────────────────┘└┘
449      rcases mem_nhds_within_iff.1 (H this) with ⟨δ, δ_pos, hδ⟩,
id              └─────────────────┘     └──┘
src      └─────┘└─────────────────┘└─┘      └───────────────────┘
typ      └─────┘└─────────────────┘└─┘ └──┘└───────────────────┘
doc      └─────┘                   └─┘      └───────────────────┘
txt      └─────┘                   └─┘      └───────────────────┘
par      └─────┘                   └─┘      └───────────────────┘
pid                               └─┘      └───────────────────┘
st   ────────────────────────────────────────────────────────────┘└─
450      exact ⟨δ, δ_pos, λx xs dx, ⟨(hδ ⟨dx, xs⟩).2, (hδ ⟨dx, xs⟩).1⟩⟩ },
id                └───┘                               └┘
src      └────┘  └┘     └┘ └───────┘       └┘  └────┘      └┘  └─────┘
typ      └────┘ └┘└───┘└┘ └───────┘       └┘  └────┘ └┘   └┘  └─────┘
doc      └────┘  └┘     └┘ └───────┘       └┘  └────┘      └┘  └─────┘
txt      └────┘  └┘     └┘ └───────┘       └┘  └────┘      └┘  └─────┘
par      └────┘  └┘     └┘ └───────┘       └┘  └────┘      └┘  └─────┘
pid             └┘     └┘ └───────┘       └┘  └────┘      └┘  └────┘
st   ──────────────────────────────────────────────────────────────────┘└┘
451    { assume H u hu,
src      └───────────┘
typ      └───────────┘
doc      └───────────┘
txt      └───────────┘
par      └───────────┘
pid      └───────────┘
st   ────────────────┘└─
452      rcases mem_nhds_within_iff.1 hu with ⟨ε, ε_pos, hε⟩,
id              └─────────────────┘   └┘
src      └─────┘└─────────────────┘└─┘  └──────────────────┘
typ      └─────┘└─────────────────┘└─┘└┘└──────────────────┘
doc      └─────┘                   └─┘  └──────────────────┘
txt      └─────┘                   └─┘  └──────────────────┘
par      └─────┘                   └─┘  └──────────────────┘
pid                               └─┘  └──────────────────┘
st   ──────────────────────────────────────────────────────┘└─
453      rcases H ε ε_pos with ⟨δ, δ_pos, hδ⟩,
id                └───┘
src      └─────┘       └──────────────────┘
typ      └─────┘└───┘└──────────────────┘
doc      └─────┘       └──────────────────┘
txt      └─────┘       └──────────────────┘
par      └─────┘       └──────────────────┘
pid                   └──────────────────┘
st   ───────────────────────────────────────┘└─
454      rw [mem_map, mem_nhds_within_iff],
id           └─────┘  └─────────────────┘
src      └──┘└─────┘└┘└─────────────────┘
typ      └──┘└─────┘└┘└─────────────────┘
doc      └──┘       └┘                   
txt      └──┘       └┘                   
par      └──┘       └┘                   
pid        └┘       └┘                   
st   ──────────────┘└───────────────────┘└──
455      exact ⟨δ, δ_pos, λx hx, hε ⟨(hδ hx.2 hx.1).2, (hδ hx.2 hx.1).1⟩⟩ }
id                └───┘         └┘                     └┘
src      └────┘  └┘     └┘ └────┘        └─┘  └─────┘     └─┘  └──────┘
typ      └────┘ └┘└───┘└┘ └────┘└┘      └─┘  └─────┘ └┘  └─┘  └──────┘
doc      └────┘  └┘     └┘ └────┘        └─┘  └─────┘     └─┘  └──────┘
txt      └────┘  └┘     └┘ └────┘        └─┘  └─────┘     └─┘  └──────┘
par      └────┘  └┘     └┘ └────┘        └─┘  └─────┘     └─┘  └──────┘
pid             └┘     └┘ └────┘        └─┘  └─────┘     └─┘  └─────┘
st   ────────────────────────────────────────────────────────────────────┘└─
456  end
st   ──┘
457  
458  @[nolint] -- see Note [nolint_ge]
doc    └────┘
459  theorem tendsto_nhds_within_nhds [metric_space β] {f : α → β} {a b} :
id                                     └──────────┘           
src                                    └──────────┘
typ                                    └──────────┘           
doc                                    └──────────┘
460    tendsto f (nhds_within a s) (𝓝 b) ↔
id     └─────┘   └─────────┘        
src    └─────┘    └─────────┘           
typ    └─────┘   └─────────┘        
doc    └─────┘    └─────────┘       
461      ∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) b < ε :=
id                                 └──┘       └──┘       
src                                     └──┘          └──┘         
typ                                └──┘       └──┘       
462  by { rw [← nhds_within_univ, tendsto_nhds_within_nhds_within], simp }
id              └──────────────┘  └─────────────────────────────┘
src       └────┘└──────────────┘└┘└─────────────────────────────┘  └───┘
typ       └────┘└──────────────┘└┘└─────────────────────────────┘  └───┘
doc       └────┘                └┘                                 └───┘
txt       └────┘                └┘                                 └───┘
par       └────┘                └┘                                 └───┘
pid         └──┘                └┘                                     
st     └───────────────────────┘└───────────────────────────────┘└──────┘└┘
463  
464  @[nolint] -- see Note [nolint_ge]
doc    └────┘
465  theorem tendsto_nhds_nhds [metric_space β] {f : α → β} {a b} :
id                              └──────────┘           
src                             └──────────┘
typ                             └──────────┘           
doc                             └──────────┘
466    tendsto f (𝓝 a) (𝓝 b) ↔
id     └─────┘          
src    └─────┘             
typ    └─────┘          
doc    └─────┘         
467      ∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε :=
id                            └──┘       └──┘       
src                              └──┘          └──┘         
typ                           └──┘       └──┘       
468  by { rw [← nhds_within_univ, ← nhds_within_univ, tendsto_nhds_within_nhds_within], simp }
id              └──────────────┘    └──────────────┘  └─────────────────────────────┘
src       └────┘└──────────────┘└──┘└──────────────┘└┘└─────────────────────────────┘  └───┘
typ       └────┘└──────────────┘└──┘└──────────────┘└┘└─────────────────────────────┘  └───┘
doc       └────┘                └──┘                └┘                                 └───┘
txt       └────┘                └──┘                └┘                                 └───┘
par       └────┘                └──┘                └┘                                 └───┘
pid         └──┘                └──┘                └┘                                     
st     └───────────────────────┘└──────────────────┘└───────────────────────────────┘└──────┘└┘
469  
470  @[nolint] -- see Note [nolint_ge]
doc    └────┘
471  theorem continuous_at_iff [metric_space β] {f : α → β} {a : α} :
id                              └──────────┘                  
src                             └──────────┘
typ                             └──────────┘                  
doc                             └──────────┘
472    continuous_at f a ↔
id     └───────────┘   
src    └───────────┘     
typ    └───────────┘   
doc    └───────────┘
473      ∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) (f a) < ε :=
id                            └──┘       └──┘          
src                              └──┘          └──┘             
typ                           └──┘       └──┘          
474  by rw [continuous_at, tendsto_nhds_nhds]
id          └───────────┘  └───────────────┘
src     └──┘└───────────┘└┘└───────────────┘└─
typ     └──┘└───────────┘└┘└───────────────┘└─
doc     └──┘└───────────┘└┘                 └─
txt     └──┘             └┘                 └─
par     └──┘             └┘                 └─
pid       └┘             └┘                 
st     └────────────────┘└─────────────────┘
475  
src  
typ  
doc  
txt  
par  
pid  
st   
476  theorem continuous_iff [metric_space β] {f : α → β} :
id                           └──────────┘           
src                          └──────────┘
typ                          └──────────┘           
doc                          └──────────┘
477    continuous f ↔
id     └────────┘  
src    └────────┘   
typ    └────────┘  
doc    └────────┘
478      ∀b (ε > 0), ∃ δ > 0, ∀a, dist a b < δ → dist (f a) (f b) < ε :=
id                          └──┘       └──┘          
src                             └──┘          └──┘             
typ                         └──┘       └──┘          
479  continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_nhds
id   └──────────────────────────┘└────┘   └──────────┘       └───────────────┘
src  └──────────────────────────┘└────┘   └──────────┘        └───────────────┘
typ  └──────────────────────────┘└────┘   └──────────┘       └───────────────┘
480  
481  theorem exists_delta_of_continuous [metric_space β] {f : α → β} {ε : ℝ}
id                                       └──────────┘                  
src                                      └──────────┘                     
typ                                      └──────────┘                  
doc                                      └──────────┘
482    (hf : continuous f) (hε : ε > 0) (b : α) :
id           └────────┘                   
src          └────────┘            
typ          └────────┘                   
doc          └────────┘
483    ∃ δ > 0, ∀a, dist a b ≤ δ → dist (f a) (f b) < ε :=
id              └──┘       └──┘          
src               └──┘          └──┘             
typ             └──┘       └──┘          
484  let ⟨δ, δ_pos, hδ⟩ := continuous_iff.1 hf b ε hε in
id   └─┘    └───┘  └┘     └────────────┘  └┘   └┘
src                        └────────────┘
typ  └─┘    └───┘  └┘     └────────────┘  └┘   └┘
485  ⟨δ / 2, half_pos δ_pos, assume a ha, hδ a $ lt_of_le_of_lt ha $ div_two_lt_of_pos δ_pos⟩
id          └──────┘                └┘        └────────────┘ └┘   └───────────────┘
src         └──────┘                            └────────────┘      └───────────────┘
typ         └──────┘                └┘        └────────────┘ └┘   └───────────────┘
486  
487  theorem tendsto_nhds {f : filter β} {u : β → α} {a : α} :
id                             └────┘                  
src                            └────┘
typ                            └────┘                  
488    tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∃ n ∈ f, ∀x ∈ n,  dist (u x) a < ε :=
id     └─────┘                            └──┘       
src    └─────┘                                    └──┘         
typ    └─────┘                            └──┘       
doc    └─────┘      
489  by simp only [metric.nhds_eq, tendsto_infi, subtype.forall, tendsto_principal, mem_ball];
id                 └────────────┘  └──────────┘  └────────────┘  └───────────────┘  └──────┘
src     └─────────┘└────────────┘└┘└──────────┘└┘└────────────┘└┘└───────────────┘└┘└──────┘
typ     └─────────┘└────────────┘└┘└──────────┘└┘└────────────┘└┘└───────────────┘└┘└──────┘
doc     └─────────┘              └┘            └┘              └┘                 └┘        
txt     └─────────┘              └┘            └┘              └┘                 └┘        
par     └─────────┘              └┘            └┘              └┘                 └┘        
pid         └──┘└┘              └┘            └┘              └┘                 └┘        
st     └───────────────────────────────────────────────────────────────────────────────────────
490    exact forall_congr (assume ε, forall_congr (assume hε, exists_sets_subset_iff.symm))
id                                   └──────────┘             └─────────────────────────┘
src    └────┘                   └──┘└──────────┘       └───┘└─────────────────────────┘└──
typ    └────┘                   └──┘└──────────┘       └───┘└─────────────────────────┘└──
doc    └────┘                   └──┘                   └───┘                           └──
txt    └────┘                   └──┘                   └───┘                           └──
par    └────┘                   └──┘                   └───┘                           └──
pid                            └──┘                   └───┘                           └┘
st   ───────────────────────────────────────────────────────────────────────────────────────
491  
src  
typ  
doc  
txt  
par  
pid  
st   
492  theorem continuous_iff' [topological_space β] {f : β → α} :
id                            └───────────────┘           
src                           └───────────────┘
typ                           └───────────────┘           
doc                           └───────────────┘
493    continuous f ↔ ∀a (ε > 0), ∃ n ∈ 𝓝 a, ∀b ∈ n, dist (f b) (f a) < ε :=
id     └────────┘                         └──┘          
src    └────────┘                                └──┘             
typ    └────────┘                         └──┘          
doc    └────────┘                       
494  continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds
id   └──────────────────────────┘└────┘   └──────────┘       └──────────┘
src  └──────────────────────────┘└────┘   └──────────┘        └──────────┘
typ  └──────────────────────────┘└────┘   └──────────┘       └──────────┘
495  
496  theorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} :
id                           └──────┘    └─────────────┘                  
src                          └──────┘     └─────────────┘
typ                          └──────┘    └─────────────┘                  
doc                                       └─────────────┘
497    tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) a < ε :=
id     └─────┘  └────┘                └──┘       
src    └─────┘   └────┘                    └──┘         
typ    └─────┘  └────┘                └──┘       
doc    └─────┘   └────┘  
498  by simp only [metric.nhds_eq, tendsto_infi, subtype.forall, tendsto_at_top_principal]; refl
id                 └────────────┘  └──────────┘  └────────────┘  └──────────────────────┘
src     └─────────┘└────────────┘└┘└──────────┘└┘└────────────┘└┘└──────────────────────┘  └────
typ     └─────────┘└────────────┘└┘└──────────┘└┘└────────────┘└┘└──────────────────────┘  └────
doc     └─────────┘              └┘            └┘              └┘                          └────
txt     └─────────┘              └┘            └┘              └┘                          └────
par     └─────────┘              └┘            └┘              └┘                          └────
pid         └──┘└┘              └┘            └┘              └┘                              
st     └─────────────────────────────────────────────────────────────────────────────────────────
499  
src  
typ  
doc  
txt  
par  
pid  
st   
500  end metric
501  
502  open metric
503  
504  @[priority 100] -- see Note [lower instance priority]
505  instance metric_space.to_separated : separated α :=
id                                        └───────┘ 
src                                       └───────┘
typ                                       └───────┘ 
506  separated_def.2 $ λ x y h, eq_of_forall_dist_le $
id   └───────────┘          └──────────────────┘
src  └───────────┘             └──────────────────┘
typ  └───────────┘          └──────────────────┘
507    λ ε ε0, le_of_lt (h _ (dist_mem_uniformity ε0))
id        └┘  └──────┘      └─────────────────┘ └┘
src            └──────┘       └─────────────────┘
typ       └┘  └──────┘      └─────────────────┘ └┘
508  
509  /-Instantiate a metric space as an emetric space. Before we can state the instance,
510  we need to show that the uniform structure coming from the edistance and the
511  distance coincide. -/
512  
513  /-- Expressing the uniformity in terms of `edist` -/
514  protected lemma metric.mem_uniformity_edist {s : set (α×α)} :
id                                                    └─┘  
src                                                   └─┘   
typ                                                   └─┘  
515    s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, edist a b < ε → (a, b) ∈ s) :=
id                       └───┘            
src                          └───┘                
typ                      └───┘            
doc        
516  begin
st   └─────
517    refine mem_uniformity_dist.trans ⟨_, _⟩; rintro ⟨ε, ε0, Hε⟩,
id            └───────────────────────┘
src    └─────┘└───────────────────────┘ └───┘  └────────────────┘
typ    └─────┘└───────────────────────┘ └───┘  └────────────────┘
doc    └─────┘                          └───┘  └────────────────┘
txt    └─────┘                          └───┘  └────────────────┘
par    └─────┘                          └───┘  └────────────────┘
pid                                    └───┘        └──────────┘
st   ────────────────────────────────────────────────────────────┘└─
518    { refine ⟨ennreal.of_real ε, _, λ a b, _⟩,
id               └─────────────┘ 
src      └─────┘ └─────────────┘ └───┘ └──────┘
typ      └─────┘ └─────────────┘└───┘ └──────┘
doc      └─────┘ └─────────────┘ └───┘ └──────┘
txt      └─────┘                 └───┘ └──────┘
par      └─────┘                 └───┘ └──────┘
pid                             └───┘ └──────┘
st   ───┘└─────────────────────────────────────┘└─
519      { rwa [gt, ennreal.of_real_pos] },
id              └┘  └─────────────────┘
src        └───┘└┘└┘└─────────────────┘└┘
typ        └───┘└┘└┘└─────────────────┘└┘
doc        └───┘  └┘                   └┘
txt        └───┘  └┘                   └┘
par        └───┘  └┘                   └┘
pid           └┘  └┘                   
st   ─────┘└─────┘└───────────────────┘└┘
520      { rw [edist_dist, ennreal.of_real_lt_of_real_iff ε0],
id             └────────┘  └────────────────────────────┘ └┘
src        └──┘└────────┘└┘└────────────────────────────┘  
typ        └──┘└────────┘└┘└────────────────────────────┘└┘
doc        └──┘          └┘                                
txt        └──┘          └┘                                
par        └──┘          └┘                                
pid          └┘          └┘                                
st   ───────────────────┘└─────────────────────────────────┘└──
521        exact Hε } },
id               └┘
src        └────┘  
typ        └────┘└┘
doc        └────┘  
txt        └────┘  
par        └────┘  
pid               
st   ──────────────┘└──┘
522    { rcases ennreal.lt_iff_exists_real_btwn.1 ε0 with ⟨ε', _, ε0', hε⟩,
id              └─────────────────────────────┘   └┘
src      └─────┘└─────────────────────────────┘└─┘  └────────────────────┘
typ      └─────┘└─────────────────────────────┘└─┘└┘└────────────────────┘
doc      └─────┘                               └─┘  └────────────────────┘
txt      └─────┘                               └─┘  └────────────────────┘
par      └─────┘                               └─┘  └────────────────────┘
pid                                           └─┘  └────────────────────┘
st   ────────────────────────────────────────────────────────────────────┘└─
523      rw [ennreal.of_real_pos] at ε0',
id           └─────────────────┘
src      └──┘└─────────────────┘└──────┘
typ      └──┘└─────────────────┘└──────┘
doc      └──┘                   └──────┘
txt      └──┘                   └──────┘
par      └──┘                   └──────┘
pid        └┘                   └─────┘
st   ──────────────────────────┘└─────┘└─
524      refine ⟨ε', ε0', λ a b h, Hε (lt_trans _ hε)⟩,
id               └┘  └─┘           └┘  └──────┘   └┘
src      └─────┘   └┘   └┘ └──────┘   └──────┘└─┘  └┘
typ      └─────┘ └┘└┘└─┘└┘ └──────┘└┘ └──────┘└─┘└┘└┘
doc      └─────┘   └┘   └┘ └──────┘           └─┘  └┘
txt      └─────┘   └┘   └┘ └──────┘           └─┘  └┘
par      └─────┘   └┘   └┘ └──────┘           └─┘  └┘
pid               └┘   └┘ └──────┘           └─┘  └┘
st   ────────────────────────────────────────────────┘└─
525      rwa [edist_dist, ennreal.of_real_lt_of_real_iff ε0'] }
id            └────────┘  └────────────────────────────┘ └─┘
src      └───┘└────────┘└┘└────────────────────────────┘   └┘
typ      └───┘└────────┘└┘└────────────────────────────┘└─┘└┘
doc      └───┘          └┘                                 └┘
txt      └───┘          └┘                                 └┘
par      └───┘          └┘                                 └┘
pid         └┘          └┘                                 
st   ──────────────────┘└──────────────────────────────────┘└─
526  end
st   ──┘
527  
528  protected theorem metric.uniformity_edist' : 𝓤 α = (⨅ε:{ε:ennreal // ε>0}, principal {p:α×α | edist p.1 p.2 < ε.val}) :=
id                                                        └─────┘       └───────┘      └───┘      └──┘
src                                                        └─────┘        └───────┘        └───┘         └──┘
typ                                                       └─────┘       └───────┘      └───┘      └──┘
doc                                                          └─────┘         └───────┘
529  begin
st   └─────
530    ext s, rw mem_infi,
id               └──────┘
src    └───┘  └─┘└──────┘
typ    └───┘  └─┘└──────┘
doc    └───┘  └─┘
txt    └───┘  └─┘
par    └───┘  └─┘
pid       └┘    
st   ──────┘└───────────┘└─
531    { simp [metric.mem_uniformity_edist, subset_def] },
id             └─────────────────────────┘  └────────┘
src      └────┘└─────────────────────────┘└┘└────────┘└┘
typ      └────┘└─────────────────────────┘└┘└────────┘└┘
doc      └────┘└─────────────────────────┘└┘          └┘
txt      └────┘                           └┘          └┘
par      └────┘                           └┘          └┘
pid                                     └┘          
st   ───┘└─────────────────────────────────────────────┘└┘
532    { rintro ⟨r, hr⟩ ⟨p, hp⟩, use ⟨min r p, lt_min hr hp⟩,
id                                    └─┘    └────┘ └┘ └┘
src      └────────────────────┘  └──┘ └─┘  └┘└────┘    
typ      └────────────────────┘  └──┘ └─┘└┘└────┘└┘└┘
doc      └────────────────────┘  └──┘      └┘          
txt      └────────────────────┘  └──┘      └┘          
par      └────────────────────┘  └──┘      └┘          
pid            └──────────────┘           └┘          
st   ───┘└────────────────────┘└───────────────────────────┘└─
533      simp [lt_min_iff, (≥)] {contextual := tt} },
id             └────────┘                     └┘
src      └────┘└────────┘└┘└──┘ └────────────┘└┘└┘
typ      └────┘└────────┘└┘└──┘ └────────────┘└┘└┘
doc      └────┘          └┘ └──┘ └────────────┘  └┘
txt      └────┘          └┘ └──┘ └────────────┘  └┘
par      └────┘          └┘ └──┘ └────────────┘  └┘
pid                    └┘ └─┘ └────────────┘  
st   ─────────────────────────────────────────────┘└┘
534    { exact ⟨⟨1, ennreal.zero_lt_one⟩⟩ }
id                  └─────────────────┘
src      └────┘  └─┘└─────────────────┘└─┘
typ      └────┘  └─┘└─────────────────┘└─┘
doc      └────┘  └─┘                   └─┘
txt      └────┘  └─┘                   └─┘
par      └────┘  └─┘                   └─┘
pid             └─┘                   └┘
st   ────────────────────────────────────┘└─
535  end
st   ──┘
536  
537  theorem uniformity_edist : 𝓤 α = (⨅ ε>0, principal {p:α×α | edist p.1 p.2 < ε}) :=
id                                      └───────┘      └───┘      
src                                       └───────┘        └───┘       
typ                                     └───────┘      └───┘      
doc                                        └───────┘
538  by simpa [infi_subtype] using @metric.uniformity_edist' α _
id             └──────────┘         └──────────────────────┘ 
src     └─────┘└──────────┘└──────┘ └──────────────────────┘ └──
typ     └─────┘└──────────┘└──────┘ └──────────────────────┘└──
doc     └─────┘            └──────┘                          └──
txt     └─────┘            └──────┘                          └──
par     └─────┘            └──────┘                          └──
pid                      └────┘                          └┘
st     └─────────────────────────────────────────────────────────
539  
src  
typ  
doc  
txt  
par  
pid  
st   
540  /-- A metric space induces an emetric space -/
541  @[priority 100] -- see Note [lower instance priority]
542  instance metric_space.to_emetric_space : emetric_space α :=
id                                            └───────────┘ 
src                                           └───────────┘
typ                                           └───────────┘ 
doc                                           └───────────┘
543  { edist               := edist,
id                            └───┘
src                           └───┘
typ                           └───┘
544    edist_self          := by simp [edist_dist],
id                                     └────────┘
src                              └────┘└────────┘
typ                              └────┘└────────┘
doc                              └────┘          
txt                              └────┘          
par                              └────┘          
pid                                            
st                              └────────────────┘
545    eq_of_edist_eq_zero := assume x y h, by simpa [edist_dist] using h,
id                                                 └────────┘        
src                                            └─────┘└────────┘└──────┘
typ                                         └─────┘└────────┘└──────┘
doc                                            └─────┘          └──────┘
txt                                            └─────┘          └──────┘
par                                            └─────┘          └──────┘
pid                                                           └────┘
st                                            └─────────────────────────┘
546    edist_comm          := by simp only [edist_dist, dist_comm]; simp,
id                                          └────────┘  └───────┘
src                              └─────────┘└────────┘└┘└───────┘  └──┘
typ                              └─────────┘└────────┘└┘└───────┘  └──┘
doc                              └─────────┘          └┘           └──┘
txt                              └─────────┘          └┘           └──┘
par                              └─────────┘          └┘           └──┘
pid                                  └──┘└┘          └┘         
st                              └──────────────────────────────────────┘
547    edist_triangle      := assume x y z, begin
id                                     
typ                                    
st                                          └─────
548      simp only [edist_dist, (ennreal.of_real_add _ _).symm, dist_nonneg],
id                  └────────┘   └─────────────────┘            └─────────┘
src      └─────────┘└────────┘└┘ └─────────────────┘└──────────┘└─────────┘
typ      └─────────┘└────────┘└┘ └─────────────────┘└──────────┘└─────────┘
doc      └─────────┘          └┘                    └──────────┘           
txt      └─────────┘          └┘                    └──────────┘           
par      └─────────┘          └┘                    └──────────┘           
pid          └──┘└┘          └┘                    └──────────┘           
st   ──────────────────────────────────────────────────────────────────────┘└─
549      rw ennreal.of_real_le_of_real_iff _,
id          └────────────────────────────┘
src      └─┘└────────────────────────────┘└┘
typ      └─┘└────────────────────────────┘└┘
doc      └─┘                              └┘
txt      └─┘                              └┘
par      └─┘                              └┘
pid                                      └┘
st   ──────────────────────────────────────┘└─
550      { exact dist_triangle _ _ _ },
id               └───────────┘
src        └────┘└───────────┘└─────┘
typ        └────┘└───────────┘└─────┘
doc        └────┘             └─────┘
txt        └────┘             └─────┘
par        └────┘             └─────┘
pid                          └────┘
st   ─────┘└────────────────────────┘└┘
551      { simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg }
id                     └────────┘                   └──┘    └─────────┘
src        └──────────┘└────────┘            └───┘└──┘  └┘└─────────┘
typ        └──────────┘└────────┘            └───┘└──┘└┘└─────────┘
doc        └──────────┘                      └───┘       └┘           
txt        └──────────┘                      └───┘       └┘           
par        └──────────┘                      └───┘       └┘           
pid             └────┘                      └───┘       └┘           
st   ─────────────────────────────────────────────────────────────────────┘└─
552    end,
st   ────┘
553    uniformity_edist    := uniformity_edist,
id                            └──────────────┘
src                           └──────────────┘
typ                           └──────────────┘
554    ..‹metric_space α› }
id       └──────────┘ 
src      └──────────┘  
typ      └──────────┘ 
doc      └──────────┘  
555  
556  /-- Balls defined using the distance or the edistance coincide -/
557  lemma metric.emetric_ball {x : α} {ε : ℝ} : emetric.ball x (ennreal.of_real ε) = ball x ε :=
id                                             └──────────┘   └─────────────┘    └──┘  
src                                             └──────────┘    └─────────────┘     └──┘
typ                                            └──────────┘   └─────────────┘    └──┘  
doc                                              └──────────┘    └─────────────┘      └──┘
558  begin
st   └─────
559    classical, by_cases h : 0 < ε,
id                                
src    └───────┘  └───────┘ └───┘
typ    └───────┘  └───────┘ └───┘
doc    └───────┘  └───────┘ └───┘ 
txt    └───────┘  └───────┘ └───┘ 
par    └───────┘  └───────┘ └───┘ 
pid                        └───┘ 
st   ──────────┘└──────────────────┘└─
560    { ext y, by simp [edist_dist, ennreal.of_real_lt_of_real_iff h] },
id                       └────────┘  └────────────────────────────┘ 
src      └───┘     └────┘└────────┘└┘└────────────────────────────┘ └┘
typ      └───┘     └────┘└────────┘└┘└────────────────────────────┘└┘
doc      └───┘     └────┘          └┘                               └┘
txt      └───┘     └────┘          └┘                               └┘
par      └───┘     └────┘          └┘                               └┘
pid         └┘                   └┘                               
st   ───┘└───┘                                                         └┘
561    { have h' : ε ≤ 0, by simpa using h,
id                                     
src      └────────┘ └┘     └──────────┘
typ      └────────┘└┘     └──────────┘
doc      └────────┘  └┘     └──────────┘
txt      └────────┘  └┘     └──────────┘
par      └────────┘  └┘     └──────────┘
pid      └─────┘└─┘            └────┘
st   ──────────────────┘                  └─
562      have A : ball x ε = ∅, by simpa [ball_eq_empty_iff_nonpos.symm],
id                └──┘    
src      └───────┘└──┘       └─────┘                             
typ      └───────┘└──┘     └─────┘└───────────────────────────┘
doc      └───────┘└──┘         └─────┘                             
txt      └───────┘             └─────┘                             
par      └───────┘             └─────┘                             
pid      └────┘└─┘                                               
st   ────────────────────────┘                                          └─
563      have B : emetric.ball x (ennreal.of_real ε) = ∅,
id                └──────────┘   └─────────────┘ 
src      └───────┘└──────────┘  └─────────────┘ └┘ 
typ      └───────┘└──────────┘ └─────────────┘└┘ 
doc      └───────┘└──────────┘  └─────────────┘ └┘ 
txt      └───────┘                              └┘ 
par      └───────┘                              └┘ 
pid      └────┘└─┘                              └┘ 
st   ──────────────────────────────────────────────────┘
564        by simp [ennreal.of_real_eq_zero.2 h', emetric.ball_eq_empty_iff],
id                  └─────────────────────┘   └┘  └───────────────────────┘
src           └────┘└─────────────────────┘└─┘  └┘└───────────────────────┘
typ           └────┘└─────────────────────┘└─┘└┘└┘└───────────────────────┘
doc           └────┘                       └─┘  └┘                         
txt           └────┘                       └─┘  └┘                         
par           └────┘                       └─┘  └┘                         
pid                                      └─┘  └┘                         
st                                                                          └─
565      rwa [A, B] }
id              
src      └───┘ └┘ └┘
typ      └───┘└┘└┘
doc      └───┘ └┘ └┘
txt      └───┘ └┘ └┘
par      └───┘ └┘ └┘
pid         └┘ └┘ 
st   ─────────┘└─┘└─
566  end
st   ──┘
567  
568  /-- Closed balls defined using the distance or the edistance coincide -/
569  lemma metric.emetric_closed_ball {x : α} {ε : ℝ} (h : 0 ≤ ε) :
id                                                          
src                                                         
typ                                                         
570    emetric.closed_ball x (ennreal.of_real ε) = closed_ball x ε :=
id     └─────────────────┘   └─────────────┘    └─────────┘  
src    └─────────────────┘    └─────────────┘     └─────────┘
typ    └─────────────────┘   └─────────────┘    └─────────┘  
doc    └─────────────────┘    └─────────────┘      └─────────┘
571  by ext y; simp [edist_dist]; rw ennreal.of_real_le_of_real_iff h
id                   └────────┘      └────────────────────────────┘ 
src     └───┘  └────┘└────────┘  └─┘└────────────────────────────┘ 
typ     └───┘  └────┘└────────┘  └─┘└────────────────────────────┘
doc     └───┘  └────┘            └─┘                               
txt     └───┘  └────┘            └─┘                               
par     └───┘  └────┘            └─┘                               
pid        └┘                                                   
st     └────────────────────────────┘└────────────────────────────┘└──
572  
src  
typ  
doc  
txt  
par  
pid  
st   
573  def metric_space.replace_uniformity {α} [U : uniform_space α] (m : metric_space α)
id                                                └───────────┘        └──────────┘ 
src                                               └───────────┘         └──────────┘
typ                                               └───────────┘        └──────────┘ 
doc                                               └───────────┘         └──────────┘
574    (H : @uniformity _ U = @uniformity _ (metric_space.to_uniform_space α)) :
id           └────────┘      └────────┘    └───────────────────────────┘ 
src          └────────┘       └────────┘    └───────────────────────────┘
typ          └────────┘      └────────┘    └───────────────────────────┘ 
doc          └────────┘        └────────┘
575    metric_space α :=
id     └──────────┘ 
src    └──────────┘
typ    └──────────┘ 
doc    └──────────┘
576  { dist               := @dist _ m.to_has_dist,
id                            └──┘   └──────────┘
src                           └──┘    └──────────┘
typ                           └──┘   └──────────┘
577    dist_self          := dist_self,
id                           └───────┘
src                          └───────┘
typ                          └───────┘
578    eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _,
id                            └────────────────┘
src                           └────────────────┘
typ                           └────────────────┘
579    dist_comm          := dist_comm,
id                           └───────┘
src                          └───────┘
typ                          └───────┘
580    dist_triangle      := dist_triangle,
id                           └───────────┘
src                          └───────────┘
typ                          └───────────┘
581    edist              := edist,
id                           └───┘
src                          └───┘
typ                          └───┘
582    edist_dist         := edist_dist,
id                           └────────┘
src                          └────────┘
typ                          └────────┘
583    to_uniform_space   := U,
id                           
typ                          
584    uniformity_dist    := H.trans (metric_space.uniformity_dist α) }
id                           └────┘  └──────────────────────────┘ 
src                           └────┘  └──────────────────────────┘
typ                          └────┘  └──────────────────────────┘ 
585  
586  /-- One gets a metric space from an emetric space if the edistance
587  is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
588  uniformity are defeq in the metric space and the emetric space. In this definition, the distance
589  is given separately, to be able to prescribe some expression which is not defeq to the push-forward
590  of the edistance to reals. -/
591  def emetric_space.to_metric_space_of_dist {α : Type u} [e : emetric_space α]
id                                                               └───────────┘ 
src                                                              └───────────┘
typ                                                              └───────────┘ 
doc                                                              └───────────┘
592    (dist : α → α → ℝ)
id                   
src                    
typ                  
593    (edist_ne_top : ∀x y: α, edist x y ≠ ⊤)
id                             └───┘    
src                             └───┘      
typ                            └───┘    
594    (h : ∀x y, dist x y = ennreal.to_real (edist x y)) :
id              └──┘    └─────────────┘  └───┘  
src                         └─────────────┘  └───┘
typ             └──┘    └─────────────┘  └───┘  
doc                          └─────────────┘
595    metric_space α :=
id     └──────────┘ 
src    └──────────┘
typ    └──────────┘ 
doc    └──────────┘
596  let m : metric_space α :=
id           └──────────┘ 
src          └──────────┘
typ          └──────────┘ 
doc          └──────────┘
597  { dist := dist,
id            └──┘
src  
typ           └──┘
598    eq_of_dist_eq_zero := λx y hxy, by simpa [h, ennreal.to_real_eq_zero_iff, edist_ne_top x y] using hxy,
id                              └─┘              └─────────────────────────┘  └──────────┘          └─┘
src                                       └─────┘ └┘└─────────────────────────┘└┘└──────────┘  └──────┘
typ                             └─┘     └─────┘└┘└─────────────────────────┘└┘└──────────┘└──────┘└─┘
doc                                       └─────┘ └┘                           └┘└──────────┘  └──────┘
txt                                       └─────┘ └┘                           └┘              └──────┘
par                                       └─────┘ └┘                           └┘              └──────┘
pid                                             └┘                           └┘              └────┘
st                                       └─────────────────────────────────────────────────────────────────┘
599    dist_self          := λx, by simp [h],
id                                       
src                                 └────┘ 
typ                                └────┘
doc                                 └────┘ 
txt                                 └────┘ 
par                                 └────┘ 
pid                                      
st                                 └───────┘
600    dist_comm          := λx y, by simp [h, emetric_space.edist_comm],
id                                          └──────────────────────┘
src                                   └────┘ └┘└──────────────────────┘
typ                                 └────┘└┘└──────────────────────┘
doc                                   └────┘ └┘                        
txt                                   └────┘ └┘                        
par                                   └────┘ └┘                        
pid                                        └┘                        
st                                   └─────────────────────────────────┘
601    dist_triangle      := λx y z, begin
id                              
typ                             
st                                   └─────
602      simp only [h],
id                  
src      └─────────┘ 
typ      └─────────┘
doc      └─────────┘ 
txt      └─────────┘ 
par      └─────────┘ 
pid          └──┘└┘ 
st   ────────────────┘└─
603      rw [← ennreal.to_real_add (edist_ne_top _ _) (edist_ne_top _ _),
id             └─────────────────┘                     └──────────┘
src      └────┘└─────────────────┘             └────┘ └──────────┘└──────
typ      └────┘└─────────────────┘             └────┘ └──────────┘└──────
doc      └────┘                                └────┘ └──────────┘└──────
txt      └────┘                                └────┘             └──────
par      └────┘                                └────┘             └──────
pid        └──┘                                └────┘             └──────
st   ──────────────────────────────────────────────────────────────────┘└─
604          ennreal.to_real_le_to_real (edist_ne_top _ _)],
id           └────────────────────────┘  └──────────┘
src  ───────┘└────────────────────────┘ └──────────┘└────┘
typ  ───────┘└────────────────────────┘ └──────────┘└────┘
doc  ───────┘                           └──────────┘└────┘
txt  ───────┘                                       └────┘
par  ───────┘                                       └────┘
pid  ───────┘                                       └────┘
st   ────────────────────────────────────────────────────┘└──
605      { exact edist_triangle _ _ _ },
id               └────────────┘
src        └────┘└────────────┘└─────┘
typ        └────┘└────────────┘└─────┘
doc        └────┘              └─────┘
txt        └────┘              └─────┘
par        └────┘              └─────┘
pid                           └────┘
st   ─────┘└─────────────────────────┘└┘
606      { simp [ennreal.add_eq_top, edist_ne_top] }
id               └────────────────┘  └──────────┘
src        └────┘└────────────────┘└┘└──────────┘└┘
typ        └────┘└────────────────┘└┘└──────────┘└┘
doc        └────┘                  └┘└──────────┘└┘
txt        └────┘                  └┘            └┘
par        └────┘                  └┘            └┘
pid                              └┘            
st   ─────────────────────────────────────────────┘└─
607    end,
st   ────┘
608    edist := λx y, edist x y,
id                  └───┘  
src                   └───┘
typ                 └───┘  
609    edist_dist := λx y, by simp [h, ennreal.of_real_to_real, edist_ne_top] } in
id                                  └─────────────────────┘  └──────────┘
src                           └────┘ └┘└─────────────────────┘└┘└──────────┘└┘
typ                         └────┘└┘└─────────────────────┘└┘└──────────┘└┘
doc                           └────┘ └┘                       └┘└──────────┘└┘
txt                           └────┘ └┘                       └┘            └┘
par                           └────┘ └┘                       └┘            └┘
pid                                └┘                       └┘            
st                           └───────────────────────────────────────────────┘
610  metric_space.replace_uniformity m (by rw [uniformity_edist, uniformity_edist']; refl)
id   └─────────────────────────────┘          └──────────────┘  └───────────────┘
src  └─────────────────────────────┘       └──┘└──────────────┘└┘└───────────────┘  └──┘
typ  └─────────────────────────────┘      └──┘└──────────────┘└┘└───────────────┘  └──┘
doc                                        └──┘                └┘└───────────────┘  └──┘
txt                                        └──┘                └┘                   └──┘
par                                        └──┘                └┘                   └──┘
pid                                          └┘                └┘                 
st                                        └───────────────────┘└─────────────────┘└────┘
611  
612  /-- One gets a metric space from an emetric space if the edistance
613  is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
614  uniformity are defeq in the metric space and the emetric space. -/
615  def emetric_space.to_metric_space {α : Type u} [e : emetric_space α] (h : ∀x y: α, edist x y ≠ ⊤) :
id                                                       └───────────┘                └───┘    
src                                                      └───────────┘                  └───┘      
typ                                                      └───────────┘                └───┘    
doc                                                      └───────────┘
616    metric_space α :=
id     └──────────┘ 
src    └──────────┘
typ    └──────────┘ 
doc    └──────────┘
617  emetric_space.to_metric_space_of_dist (λx y, ennreal.to_real (edist x y)) h (λx y, rfl)
id   └───────────────────────────────────┘      └─────────────┘  └───┘           └─┘
src  └───────────────────────────────────┘        └─────────────┘  └───┘                └─┘
typ  └───────────────────────────────────┘      └─────────────┘  └───┘           └─┘
doc  └───────────────────────────────────┘        └─────────────┘
618  
619  /-- A very useful criterion to show that a space is complete is to show that all sequences
620  which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are
621  converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
622  `0`, which makes it possible to use arguments of converging series, while this is impossible
623  to do in general for arbitrary Cauchy sequences. -/
624  theorem metric.complete_of_convergent_controlled_sequences (B : ℕ → real) (hB : ∀n, 0 < B n)
id                                                                      └──┘               
src                                                                     └──┘              
typ                                                                     └──┘               
625    (H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) → ∃x, tendsto u at_top (𝓝 x)) :
id                                        └──┘                └─────┘  └────┘   
src                                              └──┘                       └─────┘   └────┘  
typ                                       └──┘                └─────┘  └────┘   
doc                                                                                └─────┘   └────┘  
626    complete_space α :=
id     └────────────┘ 
src    └────────────┘
typ    └────────────┘ 
doc    └────────────┘
627  begin
st   └─────
628    -- this follows from the same criterion in emetric spaces. We just need to translate
st   ───────────────────────────────────────────────────────────────────────────────────────
629    -- the convergence assumption from `dist` to `edist`
st   ───────────────────────────────────────────────────────
630    apply emetric.complete_of_convergent_controlled_sequences (λn, ennreal.of_real (B n)),
id           └─────────────────────────────────────────────────┘      └─────────────┘  
src    └────┘└─────────────────────────────────────────────────┘  └─┘└─────────────┘   └┘
typ    └────┘└─────────────────────────────────────────────────┘  └─┘└─────────────┘  └┘
doc    └────┘└─────────────────────────────────────────────────┘  └─┘└─────────────┘   └┘
txt    └────┘                                                     └─┘                  └┘
par    └────┘                                                     └─┘                  └┘
pid                                                              └─┘                  └┘
st   ──────────────────────────────────────────────────────────────────────────────────────┘└─
631    { simp [hB] },
id             └┘
src      └────┘  └┘
typ      └────┘└┘└┘
doc      └────┘  └┘
txt      └────┘  └┘
par      └────┘  └┘
pid            
st   ───┘└────────┘└┘
632    { assume u Hu,
src      └─────────┘
typ      └─────────┘
doc      └─────────┘
txt      └─────────┘
par      └─────────┘
pid      └─────────┘
st   ──────────────┘└─
633      apply H,
src      └────┘
typ      └────┘
doc      └────┘
txt      └────┘
par      └────┘
pid           
st   ──────────┘└─
634      assume N n m hn hm,
src      └────────────────┘
typ      └────────────────┘
doc      └────────────────┘
txt      └────────────────┘
par      └────────────────┘
pid      └────────────────┘
st   ─────────────────────┘└─
635      rw [← ennreal.of_real_lt_of_real_iff (hB N), ← edist_dist],
id             └────────────────────────────┘  └┘      └────────┘
src      └────┘└────────────────────────────┘    └───┘└────────┘
typ      └────┘└────────────────────────────┘ └┘└───┘└────────┘
doc      └────┘                                  └───┘          
txt      └────┘                                  └───┘          
par      └────┘                                  └───┘          
pid        └──┘                                  └───┘          
st   ──────────────────────────────────────────────┘└────────────┘└──
636      exact Hu N n m hn hm }
id             └┘    └┘ └┘
src      └────┘         
typ      └────┘└┘└┘└┘
doc      └────┘         
txt      └────┘         
par      └────┘         
pid                    
st   ────────────────────────┘└─
637  end
st   ──┘
638  
639  theorem metric.complete_of_cauchy_seq_tendsto :
640    (∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) → complete_space α :=
id               └────────┘     └─────┘  └────┘        └────────────┘ 
src                 └────────┘       └─────┘   └────┘         └────────────┘
typ              └────────┘     └─────┘  └────┘        └────────────┘ 
doc                  └────────┘         └─────┘   └────┘         └────────────┘
641  emetric.complete_of_cauchy_seq_tendsto
id   └────────────────────────────────────┘
src  └────────────────────────────────────┘
typ  └────────────────────────────────────┘
doc  └────────────────────────────────────┘
642  
643  section real
644  
645  /-- Instantiate the reals as a metric space. -/
646  instance real.metric_space : metric_space ℝ :=
id                                └──────────┘ 
src                               └──────────┘ 
typ                               └──────────┘ 
doc                               └──────────┘
647  { dist               := λx y, abs (x - y),
id                              └─┘    
src                               └─┘    
typ                             └─┘    
648    dist_self          := by simp [abs_zero],
id                                    └──────┘
src                             └────┘└──────┘
typ                             └────┘└──────┘
doc                             └────┘        
txt                             └────┘        
par                             └────┘        
pid                                         
st                             └──────────────┘
649    eq_of_dist_eq_zero := by simp [add_neg_eq_zero],
id                                    └─────────────┘
src                             └────┘└─────────────┘
typ                             └────┘└─────────────┘
doc                             └────┘               
txt                             └────┘               
par                             └────┘               
pid                                                
st                             └─────────────────────┘
650    dist_comm          := assume x y, abs_sub _ _,
id                                     └─────┘
src                                      └─────┘
typ                                    └─────┘
651    dist_triangle      := assume x y z, abs_sub_le _ _ _ }
id                                      └────────┘
src                                        └────────┘
typ                                     └────────┘
652  
653  theorem real.dist_eq (x y : ℝ) : dist x y = abs (x - y) := rfl
id                                   └──┘    └─┘         └─┘
src                                  └──┘      └─┘           └─┘
typ                                  └──┘    └─┘         └─┘
654  
655  theorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x :=
id                                       └──┘     └─┘ 
src                                      └──┘      └─┘
typ                                      └──┘     └─┘ 
656  by simp [real.dist_eq]
id            └──────────┘
src     └────┘└──────────┘└─
typ     └────┘└──────────┘└─
doc     └────┘            └─
txt     └────┘            └─
par     └────┘            └─
pid                     
st     └────────────────────
657  
src  
typ  
doc  
txt  
par  
pid  
st   
658  instance : order_topology ℝ :=
id              └────────────┘ 
src             └────────────┘ 
typ             └────────────┘ 
doc             └────────────┘
659  order_topology_of_nhds_abs $ λ x, begin
id   └────────────────────────┘     
src  └────────────────────────┘
typ  └────────────────────────┘     
st                                     └─────
660    simp only [show ∀ r, {b : ℝ | abs (x - b) < r} = ball x r,
id                                  └─┘             └──┘ 
src    └─────────┘     └┘ └──┘ └─┘└─┘   └┘ └┘└──┘  └─
typ    └─────────┘     └┘ └──┘ └─┘└─┘   └┘ └┘└──┘ └─
doc    └─────────┘     └┘  └──┘ └─┘       └┘  └┘ └──┘  └─
txt    └─────────┘     └┘  └──┘ └─┘       └┘  └┘       └─
par    └─────────┘     └┘  └──┘ └─┘       └┘  └┘       └─
pid        └──┘└┘     └┘  └──┘ └─┘       └┘  └┘       └─
st   ─────────────────────────────────────────────────────────────
661      by simp [-sub_eq_add_neg, abs_sub, ball, real.dist_eq]],
id                                 └─────┘  └──┘  └──────────┘
src  ─────────────────────────────┘└─────┘└┘└──┘└┘└──────────┘└┘
typ  ─────────────────────────────┘└─────┘└┘└──┘└┘└──────────┘└┘
doc  ─────────────────────────────┘       └┘└──┘└┘            └┘
txt  ─────────────────────────────┘       └┘    └┘            └┘
par  ─────────────────────────────┘       └┘    └┘            └┘
pid  ─────────────────────────────┘       └┘    └┘            └┘
st   ─────┘└──────────────────────────────────────────────────┘└─
662    apply le_antisymm,
id           └─────────┘
src    └────┘└─────────┘
typ    └────┘└─────────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ──────────────────┘└─
663    { simp [le_infi_iff],
id             └─────────┘
src      └────┘└─────────┘
typ      └────┘└─────────┘
doc      └────┘           
txt      └────┘           
par      └────┘           
pid                     
st   ───┘└────────────────┘└─
664      exact λ ε ε0, mem_nhds_sets (is_open_ball) (mem_ball_self ε0) },
id                     └───────────┘  └──────────┘   └───────────┘
src      └────┘ └─────┘└───────────┘ └──────────┘└┘ └───────────┘  └┘
typ      └────┘ └─────┘└───────────┘ └──────────┘└┘ └───────────┘  └┘
doc      └────┘ └─────┘                          └┘                └┘
txt      └────┘ └─────┘                          └┘                └┘
par      └────┘ └─────┘                          └┘                └┘
pid            └─────┘                          └┘                
st   ─────────────────────────────────────────────────────────────────┘└┘
665    { intros s h,
src      └────────┘
typ      └────────┘
doc      └────────┘
txt      └────────┘
par      └────────┘
pid            └──┘
st   ─────────────┘└─
666      rcases mem_nhds_iff.1 h with ⟨ε, ε0, ss⟩,
id              └──────────┘   
src      └─────┘└──────────┘└─┘ └───────────────┘
typ      └─────┘└──────────┘└─┘└───────────────┘
doc      └─────┘            └─┘ └───────────────┘
txt      └─────┘            └─┘ └───────────────┘
par      └─────┘            └─┘ └───────────────┘
pid                        └─┘ └───────────────┘
st   ───────────────────────────────────────────┘└─
667      exact mem_infi_sets _ (mem_infi_sets ε0 (mem_principal_sets.2 ss)) },
id                              └───────────┘ └┘  └────────────────┘   └┘
src      └────┘             └─┘ └───────────┘   └────────────────┘└─┘  └─┘
typ      └────┘             └─┘ └───────────┘└┘ └────────────────┘└─┘└┘└─┘
doc      └────┘             └─┘                                   └─┘  └─┘
txt      └────┘             └─┘                                   └─┘  └─┘
par      └────┘             └─┘                                   └─┘  └─┘
pid                        └─┘                                   └─┘  └┘
st   ──────────────────────────────────────────────────────────────────────┘└──
668  end
st   ──┘
669  
670  lemma closed_ball_Icc {x r : ℝ} : closed_ball x r = Icc (x-r) (x+r) :=
id                                    └─────────┘    └─┘     
src                                   └─────────┘      └─┘        
typ                                   └─────────┘    └─┘     
doc                                    └─────────┘       └─┘
671  by ext y; rw [mem_closed_ball, dist_comm, real.dist_eq,
id                 └─────────────┘  └───────┘  └──────────┘
src     └───┘  └──┘└─────────────┘└┘└───────┘└┘└──────────┘└─
typ     └───┘  └──┘└─────────────┘└┘└───────┘└┘└──────────┘└─
doc     └───┘  └──┘               └┘         └┘            └─
txt     └───┘  └──┘               └┘         └┘            └─
par     └───┘  └──┘               └┘         └┘            └─
pid        └┘    └┘               └┘         └┘            └─
st     └──────────┘└─────────────┘└─────────┘└────────────┘└─
672    abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add', sub_le]
id     └────────────┘  └─────┘    └────────────────┘  └────┘
src  ─┘└────────────┘└┘└─────┘└──┘└────────────────┘└┘└────┘└─
typ  ─┘└────────────┘└┘└─────┘└──┘└────────────────┘└┘└────┘└─
doc  ─┘              └┘       └──┘                  └┘      └─
txt  ─┘              └┘       └──┘                  └┘      └─
par  ─┘              └┘       └──┘                  └┘      └─
pid  ─┘              └┘       └──┘                  └┘      
st   ───────────────┘└───────┘└────────────────────┘└──────┘
673  
src  
typ  
doc  
txt  
par  
pid  
st   
674  lemma squeeze_zero {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀t, 0 ≤ f t) (hft : ∀t, f t ≤ g t)
id                                            └────┘                                
src                                            └────┘                                     
typ                                           └────┘                                
675    (g0 : tendsto g t₀ (𝓝 0)) : tendsto f t₀ (𝓝 0) :=
id           └─────┘  └┘         └─────┘  └┘  
src          └─────┘              └─────┘       
typ          └─────┘  └┘         └─────┘  └┘  
doc          └─────┘              └─────┘       
676  begin
st   └─────
677    apply tendsto_of_tendsto_of_tendsto_of_le_of_le (tendsto_const_nhds) g0;
id           └───────────────────────────────────────┘  └────────────────┘  └┘
src    └────┘└───────────────────────────────────────┘ └────────────────┘└┘
typ    └────┘└───────────────────────────────────────┘ └────────────────┘└┘└┘
doc    └────┘└───────────────────────────────────────┘                   └┘
txt    └────┘                                                            └┘
par    └────┘                                                            └┘
pid                                                                     └┘
st   ───────────────────────────────────────────────────────────────────────────
678    simp [*]; exact filter.univ_mem_sets
src    └──────┘  └────┘                    
typ    └──────┘  └────┘                    
doc    └──────┘  └────┘                    
txt    └──────┘  └────┘                    
par    └──────┘  └────┘                    
pid        └─┘                           
st   ──────────────────────────────────────┘
679  end
st   └─┘
680  
681  theorem metric.uniformity_eq_comap_nhds_zero :
682    𝓤 α = comap (λp:α×α, dist p.1 p.2) (𝓝 (0 : ℝ)) :=
id        └───┘       └──┘             
src        └───┘         └──┘               
typ       └───┘       └──┘             
doc         └───┘                         
683  begin
st   └─────
684    simp only [uniformity_dist', nhds_eq, comap_infi, comap_principal],
id                └──────────────┘  └─────┘  └────────┘  └─────────────┘
src    └─────────┘└──────────────┘└┘└─────┘└┘└────────┘└┘└─────────────┘
typ    └─────────┘└──────────────┘└┘└─────┘└┘└────────┘└┘└─────────────┘
doc    └─────────┘                └┘       └┘          └┘               
txt    └─────────┘                └┘       └┘          └┘               
par    └─────────┘                └┘       └┘          └┘               
pid        └──┘└┘                └┘       └┘          └┘               
st   ───────────────────────────────────────────────────────────────────┘└─
685    congr, funext ε,
src    └───┘  └──────┘
typ    └───┘  └──────┘
doc           └──────┘
txt    └───┘  └──────┘
par    └───┘  └──────┘
pid                 └┘
st   ──────┘└────────┘└─
686    rw [principal_eq_iff_eq],
id         └─────────────────┘
src    └──┘└─────────────────┘
typ    └──┘└─────────────────┘
doc    └──┘                   
txt    └──┘                   
par    └──┘                   
pid      └┘                   
st   ────────────────────────┘└──
687    ext ⟨a, b⟩,
src    └────────┘
typ    └────────┘
doc    └────────┘
txt    └────────┘
par    └────────┘
pid       └─────┘
st   ───────────┘└─
688    simp [real.dist_0_eq_abs]
id           └────────────────┘
src    └────┘└────────────────┘└┘
typ    └────┘└────────────────┘└┘
doc    └────┘                  └┘
txt    └────┘                  └┘
par    └────┘                  └┘
pid                          
st   ───────────────────────────┘
689  end
st   └─┘
690  
691  lemma cauchy_seq_iff_tendsto_dist_at_top_0 [inhabited β] [semilattice_sup β] {u : β → α} :
id                                               └───────┘    └─────────────┘           
src                                              └───────┘     └─────────────┘
typ                                              └───────┘    └─────────────┘           
doc                                                            └─────────────┘
692    cauchy_seq u ↔ tendsto (λ (n : β × β), dist (u n.1) (u n.2)) at_top (𝓝 0) :=
id     └────────┘   └─────┘              └──┘            └────┘  
src    └────────┘    └─────┘                └──┘                └────┘  
typ    └────────┘   └─────┘              └──┘            └────┘  
doc    └────────┘     └─────┘                                       └────┘  
693  by rw [cauchy_seq_iff_prod_map, metric.uniformity_eq_comap_nhds_zero, ← map_le_iff_le_comap,
id          └─────────────────────┘  └──────────────────────────────────┘    └─────────────────┘
src     └──┘└─────────────────────┘└┘└──────────────────────────────────┘└──┘└─────────────────┘└─
typ     └──┘└─────────────────────┘└┘└──────────────────────────────────┘└──┘└─────────────────┘└─
doc     └──┘                       └┘                                    └──┘                   └─
txt     └──┘                       └┘                                    └──┘                   └─
par     └──┘                       └┘                                    └──┘                   └─
pid       └┘                       └┘                                    └──┘                   └─
st     └──────────────────────────┘└────────────────────────────────────┘└─────────────────────┘└─
694    filter.map_map, tendsto, prod.map_def]
id     └────────────┘  └─────┘  └──────────┘
src  ─┘└────────────┘└┘└─────┘└┘└──────────┘└─
typ  ─┘└────────────┘└┘└─────┘└┘└──────────┘└─
doc  ─┘              └┘└─────┘└┘            └─
txt  ─┘              └┘       └┘            └─
par  ─┘              └┘       └┘            └─
pid  ─┘              └┘       └┘            
st   ───────────────┘└───────┘└────────────┘
695  
src  
typ  
doc  
txt  
par  
pid  
st   
696  end real
697  
698  section cauchy_seq
699  variables [inhabited β] [semilattice_sup β]
id              └───────┘     └─────────────┘
src             └───────┘     └─────────────┘
typ             └───────┘     └─────────────┘
doc                           └─────────────┘
700  
701  /-- In a metric space, Cauchy sequences are characterized by the fact that, eventually,
702  the distance between its elements is arbitrarily small -/
703  theorem metric.cauchy_seq_iff {u : β → α} :
id                                         
typ                                        
704    cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, dist (u m) (u n) < ε :=
id     └────────┘              └──┘          
src    └────────┘                    └──┘             
typ    └────────┘              └──┘          
doc    └────────┘
705  begin
st   └─────
706    unfold cauchy_seq,
src    └───────────────┘
typ    └───────────────┘
doc    └───────────────┘
txt    └───────────────┘
par    └───────────────┘
pid          └─────────┘
st   ──────────────────┘└─
707    rw metric.cauchy_iff,
id        └───────────────┘
src    └─┘└───────────────┘
typ    └─┘└───────────────┘
doc    └─┘
txt    └─┘
par    └─┘
pid      
st   ─────────────────────┘└─
708    simp only [true_and, exists_prop, filter.mem_at_top_sets, filter.at_top_ne_bot,
id                └──────┘  └─────────┘  └────────────────────┘  └──────────────────┘
src    └─────────┘└──────┘└┘└─────────┘└┘└────────────────────┘└┘└──────────────────┘└─
typ    └─────────┘└──────┘└┘└─────────┘└┘└────────────────────┘└┘└──────────────────┘└─
doc    └─────────┘        └┘           └┘                      └┘                    └─
txt    └─────────┘        └┘           └┘                      └┘                    └─
par    └─────────┘        └┘           └┘                      └┘                    └─
pid        └──┘└┘        └┘           └┘                      └┘                    └─
st   ──────────────────────────────────────────────────────────────────────────────────
709               filter.mem_map, ne.def, filter.map_eq_bot_iff, not_false_iff, set.mem_set_of_eq],
id                └────────────┘  └────┘  └───────────────────┘  └───────────┘  └───────────────┘
src  ────────────┘└────────────┘└┘└────┘└┘└───────────────────┘└┘└───────────┘└┘└───────────────┘
typ  ────────────┘└────────────┘└┘└────┘└┘└───────────────────┘└┘└───────────┘└┘└───────────────┘
doc  ────────────┘              └┘      └┘                     └┘             └┘                 
txt  ────────────┘              └┘      └┘                     └┘             └┘                 
par  ────────────┘              └┘      └┘                     └┘             └┘                 
pid  ────────────┘              └┘      └┘                     └┘             └┘                 
st   ────────────────────────────────────────────────────────────────────────────────────────────┘└─
710    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
711    { intros H ε εpos,
src      └─────────────┘
typ      └─────────────┘
doc      └─────────────┘
txt      └─────────────┘
par      └─────────────┘
pid            └───────┘
st   ───┘└─────────────┘└─
712      rcases H ε εpos with ⟨t, ⟨N, hN⟩, ht⟩,
id                └──┘
src      └─────┘      └────────────────────┘
typ      └─────┘└──┘└────────────────────┘
doc      └─────┘      └────────────────────┘
txt      └─────┘      └────────────────────┘
par      └─────┘      └────────────────────┘
pid                  └────────────────────┘
st   ────────────────────────────────────────┘└─
713      exact ⟨N, λm n hm hn, ht _ _ (hN _ hm) (hN _ hn)⟩ },
id                            └┘                └┘
src      └────┘  └┘ └─────────┘  └───┘   └─┘  └┘   └─┘  └─┘
typ      └────┘ └┘ └─────────┘└┘└───┘   └─┘  └┘ └┘└─┘  └─┘
doc      └────┘  └┘ └─────────┘  └───┘   └─┘  └┘   └─┘  └─┘
txt      └────┘  └┘ └─────────┘  └───┘   └─┘  └┘   └─┘  └─┘
par      └────┘  └┘ └─────────┘  └───┘   └─┘  └┘   └─┘  └─┘
pid             └┘ └─────────┘  └───┘   └─┘  └┘   └─┘  └┘
st   ─────────────────────────────────────────────────────┘└┘
714    { intros H ε εpos,
src      └─────────────┘
typ      └─────────────┘
doc      └─────────────┘
txt      └─────────────┘
par      └─────────────┘
pid            └───────┘
st   ──────────────────┘└─
715      rcases H (ε/2) (half_pos εpos) with ⟨N, hN⟩,
id                    └──────┘ └──┘
src      └─────┘   └─┘ └──────┘    └────────────┘
typ      └─────┘ └─┘ └──────┘└──┘└────────────┘
doc      └─────┘    └─┘             └────────────┘
txt      └─────┘    └─┘             └────────────┘
par      └─────┘    └─┘             └────────────┘
pid                └─┘             └────────────┘
st   ──────────────────────────────────────────────┘└─
716      existsi ball (u N) (ε/2),
id               └──┘      
src      └──────┘└──┘   └┘   └┘
typ      └──────┘└──┘ └┘  └┘
doc      └──────┘└──┘   └┘   └┘
txt      └──────┘       └┘   └┘
par      └──────┘       └┘   └┘
pid                    └┘   └┘
st   ───────────────────────────┘└─
717      split,
src      └───┘
typ      └───┘
doc      └───┘
txt      └───┘
par      └───┘
st   ────────┘└─
718      { exact ⟨N, λx hx, hN _ _ hx (le_refl N)⟩ },
id                          └┘         └─────┘ 
src        └────┘  └┘ └────┘  └───┘   └─────┘ └─┘
typ        └────┘  └┘ └────┘└┘└───┘   └─────┘└─┘
doc        └────┘  └┘ └────┘  └───┘           └─┘
txt        └────┘  └┘ └────┘  └───┘           └─┘
par        └────┘  └┘ └────┘  └───┘           └─┘
pid               └┘ └────┘  └───┘           └┘
st   ─────┘└──────────────────────────────────────┘└┘
719      { exact λx y hx hy, calc
src        └────┘ └─────────┘    
typ        └────┘ └─────────┘    
doc        └────┘ └─────────┘    
txt        └────┘ └─────────┘    
par        └────┘ └─────────┘    
pid              └─────────┘    
st   ─────────────────────────────
720          dist x y ≤ dist x (u N) + dist y (u N) : dist_triangle_right _ _ _
id                                     └──┘         └─────────────────┘
src  ───────┘               └┘ └──┘    └──┘└─────────────────┘└──────
typ  ───────┘               └┘ └──┘  └──┘└─────────────────┘└──────
doc  ───────┘               └┘         └──┘                   └──────
txt  ───────┘               └┘         └──┘                   └──────
par  ───────┘               └┘         └──┘                   └──────
pid  ───────┘               └┘         └──┘                   └──────
st   ───────────────────────────────────────────────────────────────────────────
721          ... < ε/2 + ε/2 : add_lt_add hx hy
id                            └────────┘
src  ───────────┘   └┘  └──┘└────────┘    
typ  ───────────┘   └┘  └──┘└────────┘    
doc  ───────────┘   └┘   └──┘              
txt  ───────────┘   └┘   └──┘              
par  ───────────┘   └┘   └──┘              
pid  ───────────┘   └┘   └──┘              
st   ───────────────────────────────────────────
722          ... = ε : add_halves _ } }
id                    └────────┘
src  ───────────┘  └─┘└────────┘└─┘
typ  ───────────┘ └─┘└────────┘└─┘
doc  ───────────┘  └─┘          └─┘
txt  ───────────┘  └─┘          └─┘
par  ───────────┘  └─┘          └─┘
pid  ───────────┘  └─┘          └┘
st   ──────────────────────────────┘└───
723  end
st   ──┘
724  
725  /-- A variation around the metric characterization of Cauchy sequences -/
726  theorem metric.cauchy_seq_iff' {u : β → α} :
id                                          
typ                                         
727    cauchy_seq u ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) (u N) < ε :=
id     └────────┘             └──┘          
src    └────────┘                  └──┘             
typ    └────────┘             └──┘          
doc    └────────┘
728  begin
st   └─────
729    rw metric.cauchy_seq_iff,
id        └───────────────────┘
src    └─┘└───────────────────┘
typ    └─┘└───────────────────┘
doc    └─┘└───────────────────┘
txt    └─┘
par    └─┘
pid      
st   ─────────────────────────┘└─
730    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
731    { intros H ε εpos,
src      └─────────────┘
typ      └─────────────┘
doc      └─────────────┘
txt      └─────────────┘
par      └─────────────┘
pid            └───────┘
st   ───┘└─────────────┘└─
732      rcases H ε εpos with ⟨N, hN⟩,
id                └──┘
src      └─────┘      └───────────┘
typ      └─────┘└──┘└───────────┘
doc      └─────┘      └───────────┘
txt      └─────┘      └───────────┘
par      └─────┘      └───────────┘
pid                  └───────────┘
st   ───────────────────────────────┘└─
733      exact ⟨N, λn hn, hN _ _ hn (le_refl N)⟩ },
id                        └┘         └─────┘ 
src      └────┘  └┘ └────┘  └───┘   └─────┘ └─┘
typ      └────┘  └┘ └────┘└┘└───┘   └─────┘└─┘
doc      └────┘  └┘ └────┘  └───┘           └─┘
txt      └────┘  └┘ └────┘  └───┘           └─┘
par      └────┘  └┘ └────┘  └───┘           └─┘
pid             └┘ └────┘  └───┘           └┘
st   ───────────────────────────────────────────┘└┘
734    { intros H ε εpos,
src      └─────────────┘
typ      └─────────────┘
doc      └─────────────┘
txt      └─────────────┘
par      └─────────────┘
pid            └───────┘
st   ──────────────────┘└─
735      rcases H (ε/2) (half_pos εpos) with ⟨N, hN⟩,
id                    └──────┘ └──┘
src      └─────┘   └─┘ └──────┘    └────────────┘
typ      └─────┘ └─┘ └──────┘└──┘└────────────┘
doc      └─────┘    └─┘             └────────────┘
txt      └─────┘    └─┘             └────────────┘
par      └─────┘    └─┘             └────────────┘
pid                └─┘             └────────────┘
st   ──────────────────────────────────────────────┘└─
736      exact ⟨N, λ m n hm hn, calc
src      └────┘  └┘ └──────────┘    
typ      └────┘  └┘ └──────────┘    
doc      └────┘  └┘ └──────────┘    
txt      └────┘  └┘ └──────────┘    
par      └────┘  └┘ └──────────┘    
pid             └┘ └──────────┘    
st   ────────────────────────────────
737         dist (u m) (u n) ≤ dist (u m) (u N) + dist (u n) (u N) : dist_triangle_right _ _ _
id                                                └──┘             └─────────────────┘
src  ──────┘       └┘   └┘        └┘   └┘ └──┘   └┘   └──┘└─────────────────┘└──────
typ  ──────┘       └┘   └┘        └┘   └┘ └──┘   └┘ └──┘└─────────────────┘└──────
doc  ──────┘       └┘   └┘        └┘   └┘        └┘   └──┘                   └──────
txt  ──────┘       └┘   └┘        └┘   └┘        └┘   └──┘                   └──────
par  ──────┘       └┘   └┘        └┘   └┘        └┘   └──┘                   └──────
pid  ──────┘       └┘   └┘        └┘   └┘        └┘   └──┘                   └──────
st   ──────────────────────────────────────────────────────────────────────────────────────────
738                      ... < ε/2 + ε/2 : add_lt_add (hN _ hm) (hN _ hn)
id                                        └────────┘            └┘
src  ───────────────────────┘   └┘  └──┘└────────┘   └─┘  └┘   └─┘  └─
typ  ───────────────────────┘   └┘  └──┘└────────┘   └─┘  └┘ └┘└─┘  └─
doc  ───────────────────────┘   └┘   └──┘             └─┘  └┘   └─┘  └─
txt  ───────────────────────┘   └┘   └──┘             └─┘  └┘   └─┘  └─
par  ───────────────────────┘   └┘   └──┘             └─┘  └┘   └─┘  └─
pid  ───────────────────────┘   └┘   └──┘             └─┘  └┘   └─┘  └─
st   ─────────────────────────────────────────────────────────────────────
739                      ... = ε : add_halves _⟩ }
id                                └────────┘
src  ───────────────────────┘  └─┘└────────┘└──┘
typ  ───────────────────────┘ └─┘└────────┘└──┘
doc  ───────────────────────┘  └─┘          └──┘
txt  ───────────────────────┘  └─┘          └──┘
par  ───────────────────────┘  └─┘          └──┘
pid  ───────────────────────┘  └─┘          └─┘
st   ───────────────────────────────────────────┘└─
740  end
st   ──┘
741  
742  /-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N`
743  and `b` converges to zero, then `s` is a Cauchy sequence.  -/
744  lemma cauchy_seq_of_le_tendsto_0 {s : β → α} (b : β → ℝ)
id                                                      
src                                                        
typ                                                     
745    (h : ∀ n m N : β, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : tendsto b at_top (nhds 0)) :
id                                └──┘                   └─────┘  └────┘  └──┘
src                                    └──┘                         └─────┘   └────┘  └──┘
typ                               └──┘                   └─────┘  └────┘  └──┘
doc                                                                    └─────┘   └────┘  └──┘
746    cauchy_seq s :=
id     └────────┘ 
src    └────────┘
typ    └────────┘ 
doc    └────────┘
747  metric.cauchy_seq_iff.2 $ λ ε ε0,
id   └───────────────────┘       └┘
src  └───────────────────┘
typ  └───────────────────┘       └┘
doc  └───────────────────┘
748    (metric.tendsto_at_top.1 h₀ ε ε0).imp $ λ N hN m n hm hn,
id      └───────────────────┘  └┘  └┘ └─┘       └┘   └┘ └┘
src     └───────────────────┘          └─┘
typ     └───────────────────┘  └┘  └┘ └─┘       └┘   └┘ └┘
749    calc dist (s m) (s n) ≤ b N : h m n N hm hn
id          └──┘                   └┘ └┘
src         └──┘
typ         └──┘                   └┘ └┘
750                      ... ≤ abs (b N) : le_abs_self _
id                             └─┘       └─────────┘
src                            └─┘         └─────────┘
typ                            └─┘       └─────────┘
751                      ... = dist (b N) 0 : by rw real.dist_0_eq_abs; refl
id                             └──┘               └────────────────┘
src                            └──┘              └─┘└────────────────┘  └────
typ                            └──┘            └─┘└────────────────┘  └────
doc                                              └─┘                    └────
txt                                              └─┘                    └────
par                                              └─┘                    └────
pid                                                                        
st                                              └────────────────────────────
752                      ... < ε : (hN _ (le_refl N))
id                                 └┘    └─────┘ 
src  ───────────────────┘                 └─────┘
typ  ───────────────────┘          └┘    └─────┘ 
doc  ───────────────────┘
txt  ───────────────────┘
par  ───────────────────┘
pid  ───────────────────┘
st   ───────────────────┘
753  
754  /-- A Cauchy sequence on the natural numbers is bounded. -/
755  theorem cauchy_seq_bdd {u : ℕ → α} (hu : cauchy_seq u) :
id                                          └────────┘ 
src                                          └────────┘
typ                                         └────────┘ 
doc                                           └────────┘
756    ∃ R > 0, ∀ m n, dist (u m) (u n) < R :=
id                └──┘          
src                  └──┘             
typ               └──┘          
757  begin
st   └─────
758    rcases metric.cauchy_seq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩,
id            └────────────────────┘   └┘   └─────────┘
src    └─────┘└────────────────────┘└─┘  └─┘└─────────┘└───────────┘
typ    └─────┘└────────────────────┘└─┘└┘└─┘└─────────┘└───────────┘
doc    └─────┘└────────────────────┘└─┘  └─┘           └───────────┘
txt    └─────┘                      └─┘  └─┘           └───────────┘
par    └─────┘                      └─┘  └─┘           └───────────┘
pid                                └─┘  └─┘           └───────────┘
st   ──────────────────────────────────────────────────────────────┘└─
759    suffices : ∃ R > 0, ∀ n, dist (u n) (u N) < R,
id                            └──┘           
src    └─────────┘└────┘ └┘ └──┘   └┘   └┘
typ    └─────────┘└────┘ └┘ └──┘   └┘ └┘
doc    └─────────┘ └────┘  └┘        └┘   └┘ 
txt    └─────────┘ └────┘  └┘        └┘   └┘ 
par    └─────────┘ └────┘  └┘        └┘   └┘ 
pid    └───────┘└┘ └────┘  └┘        └┘   └┘ 
st   ──────────────────────────────────────────────┘└─
760    { rcases this with ⟨R, R0, H⟩,
id              └──┘
src      └─────┘    └──────────────┘
typ      └─────┘└──┘└──────────────┘
doc      └─────┘    └──────────────┘
txt      └─────┘    └──────────────┘
par      └─────┘    └──────────────┘
pid                └──────────────┘
st   ───┘└─────────────────────────┘└─
761      exact ⟨_, add_pos R0 R0, λ m n,
id                 └─────┘    └┘
src      └────┘ └─┘└─────┘    └┘ └─────
typ      └────┘ └─┘└─────┘  └┘└┘ └─────
doc      └────┘ └─┘           └┘ └─────
txt      └────┘ └─┘           └┘ └─────
par      └────┘ └─┘           └┘ └─────
pid            └─┘           └┘ └─────
st   ────────────────────────────────────
762        lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩ },
id         └────────────┘  └─────────────────┘         └────────┘        
src  ─────┘└────────────┘ └─────────────────┘└──────┘ └────────┘   └┘   └──┘
typ  ─────┘└────────────┘ └─────────────────┘└──────┘ └────────┘   └┘  └──┘
doc  ─────┘                                  └──────┘              └┘   └──┘
txt  ─────┘                                  └──────┘              └┘   └──┘
par  ─────┘                                  └──────┘              └┘   └──┘
pid  ─────┘                                  └──────┘              └┘   └─┘
st   ──────────────────────────────────────────────────────────────────────────┘└┘
763    let R := finset.sup (finset.range N) (λ n, nndist (u n) (u N)),
id              └────────┘  └──────────┘          └────┘         
src    └───────┘└────────┘ └──────────┘ └┘  └──┘└────┘   └┘   └┘
typ    └───────┘└────────┘ └──────────┘ └┘  └──┘└────┘   └┘ └┘
doc    └───────┘└────────┘ └──────────┘ └┘  └──┘└────┘   └┘   └┘
txt    └───────┘                        └┘  └──┘         └┘   └┘
par    └───────┘                        └┘  └──┘         └┘   └┘
pid    └───┘└─┘                        └┘  └──┘         └┘   └┘
st   ───────────────────────────────────────────────────────────────┘└─
764    refine ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, λ n, _⟩,
id                   └──────────────────────┘    └─────────┘
src    └─────┘  └──┘└──────────────────────┘ └─┘└─────────┘└┘ └────┘
typ    └─────┘  └──┘└──────────────────────┘└─┘└─────────┘└┘ └────┘
doc    └─────┘    └──┘                         └─┘           └┘ └────┘
txt    └─────┘    └──┘                         └─┘           └┘ └────┘
par    └─────┘    └──┘                         └─┘           └┘ └────┘
pid              └──┘                         └─┘           └┘ └────┘
st   ──────────────────────────────────────────────────────────────────┘└─
765    cases le_or_lt N n,
id           └──────┘  
src    └────┘└──────┘ 
typ    └────┘└──────┘
doc    └────┘         
txt    └────┘         
par    └────┘         
pid                  
st   ───────────────────┘└─
766    { exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2) },
id             └────────────┘  └┘      └───────────────────┘ 
src      └────┘└────────────┘   └─┘ └┘ └───────────────────┘ └──┘
typ      └────┘└────────────┘ └┘└─┘└┘ └───────────────────┘└──┘
doc      └────┘                 └─┘ └┘                       └──┘
txt      └────┘                 └─┘ └┘                       └──┘
par      └────┘                 └─┘ └┘                       └──┘
pid                            └─┘ └┘                       └─┘
st   ───┘└────────────────────────────────────────────────────────┘└┘
767    { have : _ ≤ R := finset.le_sup (finset.mem_range.2 h),
id                     └───────────┘  └──────────────┘   
src      └───────┘ └──┘└───────────┘ └──────────────┘└─┘ 
typ      └───────┘└──┘└───────────┘ └──────────────┘└─┘
doc      └───────┘  └──┘                              └─┘ 
txt      └───────┘  └──┘                              └─┘ 
par      └───────┘  └──┘                              └─┘ 
pid      └───┘└──┘  └──┘                              └─┘ 
st   ───────────────────────────────────────────────────────┘└─
768      exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one) }
id             └────────────┘ └──┘  └─────────────────┘   └─────────┘
src      └────┘└────────────┘     └─────────────────┘└─┘└─────────┘└┘
typ      └────┘└────────────┘└──┘ └─────────────────┘└─┘└─────────┘└┘
doc      └────┘                                      └─┘           └┘
txt      └────┘                                      └─┘           └┘
par      └────┘                                      └─┘           └┘
pid                                                 └─┘           
st   ─────────────────────────────────────────────────────────────────┘└─
769  end
st   ──┘
770  
771  /-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
772  most efficient. -/
773  lemma cauchy_seq_iff_le_tendsto_0 {s : ℕ → α} : cauchy_seq s ↔ ∃ b : ℕ → ℝ,
id                                                 └────────┘          
src                                                 └────────┘            
typ                                                └────────┘          
doc                                                  └────────┘
774    (∀ n, 0 ≤ b n) ∧
id                
src                  
typ               
775    (∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧
id                            └──┘             
src                               └──┘                   
typ                           └──┘             
776    tendsto b at_top (𝓝 0) :=
id     └─────┘  └────┘  
src    └─────┘   └────┘  
typ    └─────┘  └────┘  
doc    └─────┘   └────┘  
777  ⟨λ hs, begin
id      └┘
typ     └┘
st          └─────
778    /- `s` is a Cauchy sequence. The sequence `b` will be constructed by taking
st   ──────────────────────────────────────────────────────────────────────────────
779    the supremum of the distances between `s n` and `s m` for `n m ≥ N`.
st   ───────────────────────────────────────────────────────────────────────
780    First, we prove that all these distances are bounded, as otherwise the Sup
st   ─────────────────────────────────────────────────────────────────────────────
781    would not make sense. -/
st   ───────────────────────────
782    let S := λ N, (λ(p : ℕ × ℕ), dist (s p.1) (s p.2)) '' {p | p.1 ≥ N ∧ p.2 ≥ N},
id                                 └──┘                 └┘         
src    └───────┘ └──┘  └───┘  └─┘└──┘   └──┘   └───┘└┘└──┘ └─┘   └─┘  
typ    └───────┘ └──┘  └───┘  └─┘└──┘   └──┘  └───┘└┘└──┘ └─┘   └─┘  
doc    └───────┘ └──┘  └───┘   └─┘       └──┘   └───┘   └──┘ └─┘    └─┘  
txt    └───────┘ └──┘  └───┘   └─┘       └──┘   └───┘   └──┘ └─┘    └─┘  
par    └───────┘ └──┘  └───┘   └─┘       └──┘   └───┘   └──┘ └─┘    └─┘  
pid    └───┘└─┘ └──┘  └───┘   └─┘       └──┘   └───┘   └──┘ └─┘    └─┘  
st   ──────────────────────────────────────────────────────────────────────────────┘└─
783    have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x,
id                                   
src    └────────┘ └┘ └┘ └───┘    
typ    └────────┘ └┘ └┘ └───┘   
doc    └────────┘ └┘  └┘  └───┘     
txt    └────────┘ └┘  └┘  └───┘     
par    └────────┘ └┘  └┘  └───┘     
pid    └─────┘└─┘ └┘  └┘  └───┘     
st   ─────────────────────────────────────┘└─
784    { rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
id              └────────────┘ └┘
src      └─────┘└────────────┘  └───────────────┘
typ      └─────┘└────────────┘└┘└───────────────┘
doc      └─────┘└────────────┘  └───────────────┘
txt      └─────┘                └───────────────┘
par      └─────┘                └───────────────┘
pid                            └───────────────┘
st   ───┘└───────────────────────────────────────┘└─
785      refine λ N, ⟨R, _⟩, rintro _ ⟨⟨m, n⟩, _, rfl⟩,
id                    
src      └─────┘ └──┘  └──┘  └───────────────────────┘
typ      └─────┘ └──┘ └──┘  └───────────────────────┘
doc      └─────┘ └──┘  └──┘  └───────────────────────┘
txt      └─────┘ └──┘  └──┘  └───────────────────────┘
par      └─────┘ └──┘  └──┘  └───────────────────────┘
pid             └──┘  └──┘        └─────────────────┘
st   ─────────────────────┘└─────────────────────────┘└─
786      exact le_of_lt (hR m n) },
id             └──────┘  └┘  
src      └────┘└──────┘     └┘
typ      └────┘└──────┘ └┘└┘
doc      └────┘             └┘
txt      └────┘             └┘
par      └────┘             └┘
pid                        
st   ───────────────────────────┘└┘
787    have bdd : bdd_above (range (λ(p : ℕ × ℕ), dist (s p.1) (s p.2))),
id                └───────┘  └───┘                └──┘          
src    └─────────┘└───────┘ └───┘  └───┘   └─┘└──┘   └──┘   └───┘
typ    └─────────┘└───────┘ └───┘  └───┘   └─┘└──┘   └──┘  └───┘
doc    └─────────┘└───────┘ └───┘  └───┘   └─┘       └──┘   └───┘
txt    └─────────┘                 └───┘   └─┘       └──┘   └───┘
par    └─────────┘                 └───┘   └─┘       └──┘   └───┘
pid    └──────┘└─┘                 └───┘   └─┘       └──┘   └───┘
st   ──────────────────────────────────────────────────────────────────┘└─
788    { rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
id              └────────────┘ └┘
src      └─────┘└────────────┘  └───────────────┘
typ      └─────┘└────────────┘└┘└───────────────┘
doc      └─────┘└────────────┘  └───────────────┘
txt      └─────┘                └───────────────┘
par      └─────┘                └───────────────┘
pid                            └───────────────┘
st   ───┘└───────────────────────────────────────┘└─
789      use R, rintro _ ⟨⟨m, n⟩, rfl⟩, exact le_of_lt (hR m n) },
id                                           └──────┘  └┘  
src      └──┘   └────────────────────┘  └────┘└──────┘     └┘
typ      └──┘  └────────────────────┘  └────┘└──────┘ └┘└┘
doc      └──┘   └────────────────────┘  └────┘             └┘
txt      └──┘   └────────────────────┘  └────┘             └┘
par      └──┘   └────────────────────┘  └────┘             └┘
pid                  └──────────────┘                    
st   ────────┘└──────────────────────┘└────────────────────────┘└┘
790    -- Prove that it bounds the distances of points in the Cauchy sequence
st   ─────────────────────────────────────────────────────────────────────────
791    have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ real.Sup (S N) :=
id                                       └──┘              └──────┘  
src    └────────┘ └────┘         └──┘   └┘   └┘ └──────┘   └────
typ    └────────┘ └────┘        └──┘   └┘  └┘ └──────┘  └────
doc    └────────┘ └────┘                └┘   └┘            └────
txt    └────────┘ └────┘                └┘   └┘            └────
par    └────────┘ └────┘                └┘   └┘            └────
pid    └─────┘└─┘ └────┘                └┘   └┘            └───
st   ──────────────────────────────────────────────────────────────────────────
792      λ m n N hm hn, real.le_Sup _ (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩,
id                      └─────────┘    └┘                       └─┘
src  ───┘ └────────────┘└─────────┘└─┘    └┘  └─────┘   └┘  └─┘└─┘
typ  ───┘ └────────────┘└─────────┘└─┘ └┘ └┘  └─────┘   └┘  └─┘└─┘
doc  ───┘ └────────────┘           └─┘    └┘  └─────┘   └┘  └─┘   
txt  ───┘ └────────────┘           └─┘    └┘  └─────┘   └┘  └─┘   
par  ───┘ └────────────┘           └─┘    └┘  └─────┘   └┘  └─┘   
pid  ───┘ └────────────┘           └─┘    └┘  └─────┘   └┘  └─┘   
st   ──────────────────────────────────────────────────────────────┘└─
793    have S0m : ∀ n, (0:ℝ) ∈ S n := λ n, ⟨⟨n, n⟩, ⟨le_refl _, le_refl _⟩, dist_self _⟩,
id                                                             └─────┘     └───────┘
src    └─────────┘ └┘  └┘ └┘   └──┘ └──┘   └┘ └─┘        └──┘└─────┘└───┘└───────┘└─┘
typ    └─────────┘ └┘  └┘ └┘  └──┘ └──┘   └┘ └─┘        └──┘└─────┘└───┘└───────┘└─┘
doc    └─────────┘ └┘  └┘ └┘   └──┘ └──┘   └┘ └─┘        └──┘       └───┘         └─┘
txt    └─────────┘ └┘  └┘ └┘   └──┘ └──┘   └┘ └─┘        └──┘       └───┘         └─┘
par    └─────────┘ └┘  └┘ └┘   └──┘ └──┘   └┘ └─┘        └──┘       └───┘         └─┘
pid    └──────┘└─┘ └┘  └┘ └┘   └──┘ └──┘   └┘ └─┘        └──┘       └───┘         └─┘
st   ──────────────────────────────────────────────────────────────────────────────────┘└─
794    have S0 := λ n, real.le_Sup _ (hS n) (S0m n),
id                     └─────────┘    └┘     └─┘
src    └─────────┘ └──┘└─────────┘└─┘    └┘     
typ    └─────────┘ └──┘└─────────┘└─┘ └┘ └┘ └─┘ 
doc    └─────────┘ └──┘           └─┘    └┘     
txt    └─────────┘ └──┘           └─┘    └┘     
par    └─────────┘ └──┘           └─┘    └┘     
pid    └─────┘└─┘ └──┘           └─┘    └┘     
st   ─────────────────────────────────────────────┘└─
795    -- Prove that it tends to `0`, by using the Cauchy property of `s`
st   ─────────────────────────────────────────────────────────────────────
796    refine ⟨λ N, real.Sup (S N), S0, ub, metric.tendsto_at_top.2 (λ ε ε0, _)⟩,
id                  └──────┘       └┘  └┘  └───────────────────┘
src    └─────┘  └──┘└──────┘   └─┘  └┘  └┘└───────────────────┘└─┘  └────────┘
typ    └─────┘  └──┘└──────┘  └─┘└┘└┘└┘└┘└───────────────────┘└─┘  └────────┘
doc    └─────┘  └──┘           └─┘  └┘  └┘                     └─┘  └────────┘
txt    └─────┘  └──┘           └─┘  └┘  └┘                     └─┘  └────────┘
par    └─────┘  └──┘           └─┘  └┘  └┘                     └─┘  └────────┘
pid            └──┘           └─┘  └┘  └┘                     └─┘  └────────┘
st   ──────────────────────────────────────────────────────────────────────────┘└─
797    refine (metric.cauchy_seq_iff.1 hs (ε/2) (half_pos ε0)).imp (λ N hN n hn, _),
id             └───────────────────┘   └┘      └──────┘ └┘
src    └─────┘ └───────────────────┘└─┘    └─┘ └──────┘  └─────┘  └────────────┘
typ    └─────┘ └───────────────────┘└─┘└┘ └─┘ └──────┘└┘└─────┘  └────────────┘
doc    └─────┘ └───────────────────┘└─┘     └─┘           └─────┘  └────────────┘
txt    └─────┘                      └─┘     └─┘           └─────┘  └────────────┘
par    └─────┘                      └─┘     └─┘           └─────┘  └────────────┘
pid                                └─┘     └─┘           └─────┘  └────────────┘
st   ─────────────────────────────────────────────────────────────────────────────┘└─
798    rw [real.dist_0_eq_abs, abs_of_nonneg (S0 n)],
id         └────────────────┘  └───────────┘  └┘ 
src    └──┘└────────────────┘└┘└───────────┘    └┘
typ    └──┘└────────────────┘└┘└───────────┘ └┘└┘
doc    └──┘                  └┘                 └┘
txt    └──┘                  └┘                 └┘
par    └──┘                  └┘                 └┘
pid      └┘                  └┘                 └┘
st   ───────────────────────┘└────────────────────┘└──
799    refine lt_of_le_of_lt (real.Sup_le_ub _ ⟨_, S0m _⟩ _) (half_lt_self ε0),
id            └────────────┘  └────────────┘       └─┘        └──────────┘ └┘
src    └─────┘└────────────┘ └────────────┘└─┘ └─┘   └─────┘ └──────────┘  
typ    └─────┘└────────────┘ └────────────┘└─┘ └─┘└─┘└─────┘ └──────────┘└┘
doc    └─────┘                             └─┘ └─┘   └─────┘               
txt    └─────┘                             └─┘ └─┘   └─────┘               
par    └─────┘                             └─┘ └─┘   └─────┘               
pid                                       └─┘ └─┘   └─────┘               
st   ────────────────────────────────────────────────────────────────────────┘└─
800    rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩,
src    └──────────────────────────────────┘
typ    └──────────────────────────────────┘
doc    └──────────────────────────────────┘
txt    └──────────────────────────────────┘
par    └──────────────────────────────────┘
pid          └────────────────────────────┘
st   ─────────────────────────────────────┘└─
801    exact le_of_lt (hN _ _ (le_trans hn hm') (le_trans hn hn'))
id           └──────┘  └┘                  └─┘   └──────┘ └┘ └─┘
src    └────┘└──────┘   └───┘              └┘ └──────┘     └──
typ    └────┘└──────┘ └┘└───┘           └─┘└┘ └──────┘└┘└─┘└──
doc    └────┘           └───┘              └┘              └──
txt    └────┘           └───┘              └┘              └──
par    └────┘           └───┘              └┘              └──
pid                    └───┘              └┘              └┘
st   ──────────────────────────────────────────────────────────────
802    end,
src  ─┘
typ  ─┘
doc  ─┘
txt  ─┘
par  ─┘
pid  ─┘
st   ─┘└─┘
803  λ ⟨b, _, b_bound, b_lim⟩, cauchy_seq_of_le_tendsto_0 b b_bound b_lim⟩
id          └─────┘  └───┘   └────────────────────────┘
src                            └────────────────────────┘
typ         └─────┘  └───┘   └────────────────────────┘
doc                            └────────────────────────┘
804  
805  end cauchy_seq
806  
807  def metric_space.induced {α β} (f : α → β) (hf : function.injective f)
id                                                  └────────────────┘ 
src                                                   └────────────────┘
typ                                                 └────────────────┘ 
808    (m : metric_space β) : metric_space α :=
id          └──────────┘     └──────────┘ 
src         └──────────┘      └──────────┘
typ         └──────────┘     └──────────┘ 
doc         └──────────┘      └──────────┘
809  { dist               := λ x y, dist (f x) (f y),
id                                └──┘       
src                                 └──┘
typ                               └──┘       
810    dist_self          := λ x, dist_self _,
id                               └───────┘
src                               └───────┘
typ                              └───────┘
811    eq_of_dist_eq_zero := λ x y h, hf (dist_eq_zero.1 h),
id                                 └┘  └──────────┘  
src                                       └──────────┘
typ                                └┘  └──────────┘  
812    dist_comm          := λ x y, dist_comm _ _,
id                                └───────┘
src                                 └───────┘
typ                               └───────┘
813    dist_triangle      := λ x y z, dist_triangle _ _ _,
id                                 └───────────┘
src                                   └───────────┘
typ                                └───────────┘
814    edist              := λ x y, edist (f x) (f y),
id                                └───┘       
src                                 └───┘
typ                               └───┘       
815    edist_dist         := λ x y, edist_dist _ _,
id                                └────────┘
src                                 └────────┘
typ                               └────────┘
816    to_uniform_space   := uniform_space.comap f m.to_uniform_space,
id                           └─────────────────┘  └───────────────┘
src                          └─────────────────┘    └───────────────┘
typ                          └─────────────────┘  └───────────────┘
doc                          └─────────────────┘
817    uniformity_dist    := begin
st                           └─────
818      apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, dist (f x) (f y)),
id              └───────────────────────────────┘                   └──┘        
src      └────┘ └───────────────────────────────┘└─────────┘  └────┘└──┘   └┘   └┘
typ      └────┘ └───────────────────────────────┘└─────────┘  └────┘└──┘   └┘  └┘
doc      └────┘ └───────────────────────────────┘└─────────┘  └────┘       └┘   └┘
txt      └────┘                                  └─────────┘  └────┘       └┘   └┘
par      └────┘                                  └─────────┘  └────┘       └┘   └┘
pid                                             └─────────┘  └────┘       └┘   └┘
st   ───────────────────────────────────────────────────────────────────────────────┘└─
819      refine λ s, mem_comap_sets.trans _,
id                   └──────────────────┘
src      └─────┘ └──┘└──────────────────┘└┘
typ      └─────┘ └──┘└──────────────────┘└┘
doc      └─────┘ └──┘                    └┘
txt      └─────┘ └──┘                    └┘
par      └─────┘ └──┘                    └┘
pid             └──┘                    └┘
st   ─────────────────────────────────────┘└─
820      split; intro H,
src      └───┘  └─────┘
typ      └───┘  └─────┘
doc      └───┘  └─────┘
txt      └───┘  └─────┘
par      └───┘  └─────┘
pid                  └┘
st   ─────────────────┘└─
821      { rcases H with ⟨r, ru, rs⟩,
id                
src        └─────┘ └───────────────┘
typ        └─────┘└───────────────┘
doc        └─────┘ └───────────────┘
txt        └─────┘ └───────────────┘
par        └─────┘ └───────────────┘
pid               └───────────────┘
st   ─────┘└───────────────────────┘└─
822        rcases mem_uniformity_dist.1 ru with ⟨ε, ε0, hε⟩,
id                └─────────────────┘   └┘
src        └─────┘└─────────────────┘└─┘  └───────────────┘
typ        └─────┘└─────────────────┘└─┘└┘└───────────────┘
doc        └─────┘                   └─┘  └───────────────┘
txt        └─────┘                   └─┘  └───────────────┘
par        └─────┘                   └─┘  └───────────────┘
pid                                 └─┘  └───────────────┘
st   ─────────────────────────────────────────────────────┘└─
823        refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
id                   └┘           └┘  └┘            
src        └─────┘  └┘  └┘ └──────┘     └──┘  └────┘ 
typ        └─────┘ └┘└┘└┘ └──────┘└┘ └┘└──┘  └────┘
doc        └─────┘  └┘  └┘ └──────┘     └──┘  └────┘ 
txt        └─────┘  └┘  └┘ └──────┘     └──┘  └────┘ 
par        └─────┘  └┘  └┘ └──────┘     └──┘  └────┘ 
pid                └┘  └┘ └──────┘     └──┘        
st   ───────────────────────────────────────┘└────────┘└┘
824      { rcases H with ⟨ε, ε0, hε⟩,
id                
src        └─────┘ └───────────────┘
typ        └─────┘└───────────────┘
doc        └─────┘ └───────────────┘
txt        └─────┘ └───────────────┘
par        └─────┘ └───────────────┘
pid               └───────────────┘
st   ──────────────────────────────┘└─
825        exact ⟨_, dist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
id                   └─────────────────┘ └┘            └┘
src        └────┘ └─┘└─────────────────┘  └┘ └┘ └┘ └─┘  └┘
typ        └────┘ └─┘└─────────────────┘└┘└┘ └┘ └┘ └─┘└┘└┘
doc        └────┘ └─┘                     └┘ └┘ └┘ └─┘  └┘
txt        └────┘ └─┘                     └┘ └┘ └┘ └─┘  └┘
par        └────┘ └─┘                     └┘ └┘ └┘ └─┘  └┘
pid              └─┘                     └┘ └┘ └┘ └─┘  
st   ─────────────────────────────────────────────────────┘└─
826    end }
st   ────┘
827  
828  instance subtype.metric_space {α : Type*} {p : α → Prop} [t : metric_space α] :
id                                                                └──────────┘ 
src                                                                └──────────┘
typ                                                               └──────────┘ 
doc                                                                └──────────┘
829    metric_space (subtype p) :=
id     └──────────┘  └─────┘ 
src    └──────────┘  └─────┘
typ    └──────────┘  └─────┘ 
doc    └──────────┘
830  metric_space.induced subtype.val (λ x y, subtype.eq) t
id   └──────────────────┘ └─────────┘       └────────┘  
src  └──────────────────┘ └─────────┘         └────────┘
typ  └──────────────────┘ └─────────┘       └────────┘  
831  
832  theorem subtype.dist_eq {p : α → Prop} (x y : subtype p) : dist x y = dist x.1 y.1 := rfl
id                                                └─────┘     └──┘    └──┘        └─┘
src                                                └─────┘      └──┘      └──┘          └─┘
typ                                               └─────┘     └──┘    └──┘        └─┘
833  
834  section nnreal
835  
836  instance : metric_space nnreal := by unfold nnreal; apply_instance
id              └──────────┘ └────┘
src             └──────────┘ └────┘       └───────────┘  └──────────────
typ             └──────────┘ └────┘       └───────────┘  └──────────────
doc             └──────────┘ └────┘       └───────────┘  └──────────────
txt                                       └───────────┘  └──────────────
par                                       └───────────┘  └──────────────
pid                                             └─────┘                
st                                       └──────────────────────────────
837  
src  
typ  
doc  
txt  
par  
pid  
st   
838  lemma nnreal.dist_eq (a b : nnreal) : dist a b = abs ((a:ℝ) - b) := rfl
id                               └────┘    └──┘    └─┘            └─┘
src                              └────┘    └──┘      └─┘              └─┘
typ                              └────┘    └──┘    └─┘            └─┘
doc                              └────┘
839  
840  lemma nnreal.nndist_eq (a b : nnreal) :
id                                 └────┘
src                                └────┘
typ                                └────┘
doc                                └────┘
841    nndist a b = max (a - b) (b - a) :=
id     └────┘    └─┘         
src    └────┘      └─┘           
typ    └────┘    └─┘         
doc    └────┘
842  begin
st   └─────
843    wlog h : a ≤ b,
id                
src    └───────┘ 
typ    └───────┘
doc    └───────┘  
txt    └───────┘  
par    └───────┘  
pid        └┘└─┘  
st   ───────────────┘└─
844    { apply nnreal.coe_eq.1,
id             └───────────┘
src      └────┘└───────────┘└┘
typ      └────┘└───────────┘└┘
doc      └────┘             └┘
txt      └────┘             └┘
par      └────┘             └┘
pid                        └┘
st   ───┘└───────────────────┘└─
845      rw [nnreal.sub_eq_zero h, max_eq_right (zero_le $ b - a), ← dist_nndist, nnreal.dist_eq,
id           └────────────────┘   └──────────┘  └─────┘          └─────────┘  └────────────┘
src      └──┘└────────────────┘ └┘└──────────┘ └─────┘   └───┘└─────────┘└┘└────────────┘└─
typ      └──┘└────────────────┘└┘└──────────┘ └─────┘ └───┘└─────────┘└┘└────────────┘└─
doc      └──┘                   └┘                        └───┘└─────────┘└┘              └─
txt      └──┘                   └┘                        └───┘           └┘              └─
par      └──┘                   └┘                        └───┘           └┘              └─
pid        └┘                   └┘                        └───┘           └┘              └─
st   ───────────────────────────┘└──────────────────────────────┘└─────────────┘└──────────────┘└─
846        nnreal.coe_sub h, abs, neg_sub],
id         └────────────┘   └─┘  └─────┘
src  ─────┘└────────────┘ └┘└─┘└┘└─────┘
typ  ─────┘└────────────┘└┘└─┘└┘└─────┘
doc  ─────┘               └┘   └┘       
txt  ─────┘               └┘   └┘       
par  ─────┘               └┘   └┘       
pid  ─────┘               └┘   └┘       
st   ─────────────────────┘└───┘└───────┘└──
847      apply max_eq_right,
id             └──────────┘
src      └────┘└──────────┘
typ      └────┘└──────────┘
doc      └────┘
txt      └────┘
par      └────┘
pid           
st   ─────────────────────┘└─
848      linarith [nnreal.coe_le.2 h] },
id                 └───────────┘   
src      └────────┘└───────────┘└─┘ └┘
typ      └────────┘└───────────┘└─┘└┘
doc      └────────┘             └─┘ └┘
txt      └────────┘             └─┘ └┘
par      └────────┘             └─┘ └┘
pid                           └─┘ 
st   ────────────────────────────────┘└┘
849    rwa [nndist_comm, max_comm]
id          └─────────┘  └──────┘
src    └───┘└─────────┘└┘└──────┘└┘
typ    └───┘└─────────┘└┘└──────┘└┘
doc    └───┘           └┘        └┘
txt    └───┘           └┘        └┘
par    └───┘           └┘        └┘
pid       └┘           └┘        
st   ─────────────────┘└────────┘
850  end
st   └─┘
851  end nnreal
852  
853  section prod
854  
855  instance prod.metric_space_max [metric_space β] : metric_space (α × β) :=
id                                   └──────────┘     └──────────┘    
src                                  └──────────┘      └──────────┘    
typ                                  └──────────┘     └──────────┘    
doc                                  └──────────┘      └──────────┘
856  { dist := λ x y, max (dist x.1 y.1) (dist x.2 y.2),
id                  └─┘  └──┘       └──┘   
src                   └─┘  └──┘         └──┘     
typ                 └─┘  └──┘       └──┘   
857    dist_self := λ x, by simp,
id                    
src                         └──┘
typ                        └──┘
doc                         └──┘
txt                         └──┘
par                         └──┘
st                         └───┘
858    eq_of_dist_eq_zero := λ x y h, begin
id                               
typ                              
st                                    └─────
859      cases max_le_iff.1 (le_of_eq h) with h₁ h₂,
id             └────────┘    └──────┘ 
src      └────┘└────────┘└─┘ └──────┘ └──────────┘
typ      └────┘└────────┘└─┘ └──────┘└──────────┘
doc      └────┘          └─┘          └──────────┘
txt      └────┘          └─┘          └──────────┘
par      └────┘          └─┘          └──────────┘
pid                     └─┘          └─────────┘
st   ─────────────────────────────────────────────┘└─
860      exact prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩
id             └──────────┘                   └┘  └──────────┘   └┘
src      └────┘└──────────┘└─┘             └─┘  └┘└──────────┘└─┘  └─
typ      └────┘└──────────┘└─┘             └─┘└┘└┘└──────────┘└─┘└┘└─
doc      └────┘            └─┘             └─┘  └┘            └─┘  └─
txt      └────┘            └─┘             └─┘  └┘            └─┘  └─
par      └────┘            └─┘             └─┘  └┘            └─┘  └─
pid                       └─┘             └─┘  └┘            └─┘  
st   ────────────────────────────────────────────────────────────────
861    end,
src  ─┘
typ  ─┘
doc  ─┘
txt  ─┘
par  ─┘
pid  ─┘
st   ─┘└─┘
862    dist_comm := λ x y, by simp [dist_comm],
id                                └───────┘
src                           └────┘└───────┘
typ                         └────┘└───────┘
doc                           └────┘         
txt                           └────┘         
par                           └────┘         
pid                                        
st                           └───────────────┘
863    dist_triangle := λ x y z, max_le
id                            └────┘
src                              └────┘
typ                           └────┘
864      (le_trans (dist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
id        └──────┘  └───────────┘         └────────┘  └─────────┘       └─────────┘
src       └──────┘  └───────────┘         └────────┘  └─────────┘       └─────────┘
typ       └──────┘  └───────────┘         └────────┘  └─────────┘       └─────────┘
865      (le_trans (dist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
id        └──────┘  └───────────┘         └────────┘  └──────────┘       └──────────┘
src       └──────┘  └───────────┘         └────────┘  └──────────┘       └──────────┘
typ       └──────┘  └───────────┘         └────────┘  └──────────┘       └──────────┘
866    edist := λ x y, max (edist x.1 y.1) (edist x.2 y.2),
id                   └─┘  └───┘       └───┘   
src                    └─┘  └───┘         └───┘     
typ                  └─┘  └───┘       └───┘   
867    edist_dist := assume x y, begin
id                           
typ                          
st                               └─────
868      have : monotone ennreal.of_real := assume x y h, ennreal.of_real_le_of_real h,
id              └──────┘ └─────────────┘                  └────────────────────────┘
src      └─────┘└──────┘└─────────────┘└──┘      └──────┘└────────────────────────┘
typ      └─────┘└──────┘└─────────────┘└──┘      └──────┘└────────────────────────┘
doc      └─────┘└──────┘└─────────────┘└──┘      └──────┘                          
txt      └─────┘                       └──┘      └──────┘                          
par      └─────┘                       └──┘      └──────┘                          
pid      └───┘└┘                       └──┘      └──────┘                          
st   ────────────────────────────────────────────────────────────────────────────────┘└─
869      rw [edist_dist, edist_dist, this.map_max.symm]
id           └────────┘  └────────┘
src      └──┘└────────┘└┘└────────┘└┘                 └─
typ      └──┘└────────┘└┘└────────┘└┘└───────────────┘└─
doc      └──┘          └┘          └┘                 └─
txt      └──┘          └┘          └┘                 └─
par      └──┘          └┘          └┘                 └─
pid        └┘          └┘          └┘                 
st   ─────────────────┘└──────────┘└─────────────────┘
870    end,
src  ─┘
typ  ─┘
doc  ─┘
txt  ─┘
par  ─┘
pid  ─┘
st   ─┘└─┘
871    uniformity_dist := begin
st                        └─────
872      refine uniformity_prod.trans _,
id              └───────────────────┘
src      └─────┘└───────────────────┘└┘
typ      └─────┘└───────────────────┘└┘
doc      └─────┘                     └┘
txt      └─────┘                     └┘
par      └─────┘                     └┘
pid                                 └┘
st   ─────────────────────────────────┘└─
873      simp [uniformity_dist, comap_infi],
id             └─────────────┘  └────────┘
src      └────┘└─────────────┘└┘└────────┘
typ      └────┘└─────────────┘└┘└────────┘
doc      └────┘               └┘          
txt      └────┘               └┘          
par      └────┘               └┘          
pid                         └┘          
st   ─────────────────────────────────────┘└─
874      rw ← infi_inf_eq, congr, funext,
id            └─────────┘
src      └───┘└─────────┘  └───┘  └────┘
typ      └───┘└─────────┘  └───┘  └────┘
doc      └───┘                    └────┘
txt      └───┘             └───┘  └────┘
par      └───┘             └───┘  └────┘
pid        └─┘
st   ───────────────────┘└─────┘└──────┘└─
875      rw ← infi_inf_eq, congr, funext,
id            └─────────┘
src      └───┘└─────────┘  └───┘  └────┘
typ      └───┘└─────────┘  └───┘  └────┘
doc      └───┘                    └────┘
txt      └───┘             └───┘  └────┘
par      └───┘             └───┘  └────┘
pid        └─┘
st   ───────────────────┘└─────┘└──────┘└─
876      simp [inf_principal, ext_iff, max_lt_iff]
id             └───────────┘  └─────┘  └────────┘
src      └────┘└───────────┘└┘└─────┘└┘└────────┘└─
typ      └────┘└───────────┘└┘└─────┘└┘└────────┘└─
doc      └────┘             └┘       └┘          └─
txt      └────┘             └┘       └┘          └─
par      └────┘             └┘       └┘          └─
pid                       └┘       └┘          
st   ──────────────────────────────────────────────
877    end,
src  ─┘
typ  ─┘
doc  ─┘
txt  ─┘
par  ─┘
pid  ─┘
st   ─┘└─┘
878    to_uniform_space := prod.uniform_space }
id                         └────────────────┘
src                        └────────────────┘
typ                        └────────────────┘
879  
880  lemma prod.dist_eq [metric_space β] {x y : α × β} :
id                       └──────────┘            
src                      └──────────┘             
typ                      └──────────┘            
doc                      └──────────┘
881    dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl
id     └──┘    └─┘  └──┘       └──┘         └─┘
src    └──┘      └─┘  └──┘         └──┘           └─┘
typ    └──┘    └─┘  └──┘       └──┘         └─┘
882  
883  end prod
884  
885  theorem uniform_continuous_dist' : uniform_continuous (λp:α×α, dist p.1 p.2) :=
id                                      └────────────────┘       └──┘   
src                                     └────────────────┘         └──┘     
typ                                     └────────────────┘       └──┘   
886  metric.uniform_continuous_iff.2 (λ ε ε0, ⟨ε/2, half_pos ε0,
id   └───────────────────────────┘      └┘      └──────┘ └┘
src  └───────────────────────────┘                └──────┘
typ  └───────────────────────────┘      └┘      └──────┘ └┘
887  begin
st   └─────
888    suffices,
src    └──────┘
typ    └──────┘
doc    └──────┘
txt    └──────┘
par    └──────┘
pid    └──────┘
st   ─────────┘└─
889    { intros p q h, cases p with p₁ p₂, cases q with q₁ q₂,
id                                              
src      └──────────┘  └────┘ └─────────┘  └────┘ └─────────┘
typ      └──────────┘  └────┘└─────────┘  └────┘└─────────┘
doc      └──────────┘  └────┘ └─────────┘  └────┘ └─────────┘
txt      └──────────┘  └────┘ └─────────┘  └────┘ └─────────┘
par      └──────────┘  └────┘ └─────────┘  └────┘ └─────────┘
pid            └────┘        └─────────┘        └─────────┘
st   ───┘└──────────┘└──────────────────┘└──────────────────┘└─
890      cases max_lt_iff.1 h with h₁ h₂, clear h,
id             └────────┘   
src      └────┘└────────┘└─┘ └─────────┘  └─────┘
typ      └────┘└────────┘└─┘└─────────┘  └─────┘
doc      └────┘          └─┘ └─────────┘  └─────┘
txt      └────┘          └─┘ └─────────┘  └─────┘
par      └────┘          └─┘ └─────────┘  └─────┘
pid                     └─┘ └─────────┘       └┘
st   ──────────────────────────────────┘└───────┘└─
891      dsimp at h₁ h₂ ⊢,
src      └──────────────┘
typ      └──────────────┘
doc      └──────────────┘
txt      └──────────────┘
par      └──────────────┘
pid           └────────┘
st   ───────────────────┘└─
892      rw real.dist_eq,
id          └──────────┘
src      └─┘└──────────┘
typ      └─┘└──────────┘
doc      └─┘
txt      └─┘
par      └─┘
pid        
st   ──────────────────┘└─
893      refine abs_sub_lt_iff.2 ⟨_, _⟩,
id              └────────────┘
src      └─────┘└────────────┘└─┘ └───┘
typ      └─────┘└────────────┘└─┘ └───┘
doc      └─────┘              └─┘ └───┘
txt      └─────┘              └─┘ └───┘
par      └─────┘              └─┘ └───┘
pid                          └─┘ └───┘
st   ─────────────────────────────────┘└─
894      { revert p₁ p₂ q₁ q₂ h₁ h₂, exact this },
id                                         └──┘
src        └──────────────────────┘  └────┘    
typ        └──────────────────────┘  └────┘└──┘
doc        └──────────────────────┘  └────┘    
txt        └──────────────────────┘  └────┘    
par        └──────────────────────┘  └────┘    
pid              └────────────────┘           
st   ─────┘└──────────────────────┘└───────────┘└┘
895      { apply this; rwa dist_comm } },
id                         └───────┘
src        └────┘      └──┘└───────┘
typ        └────┘      └──┘└───────┘
doc        └────┘      └──┘         
txt        └────┘      └──┘         
par        └────┘      └──┘         
pid                               
st   ─────────────────────┘└───────┘└──┘
896    intros p₁ p₂ q₁ q₂ h₁ h₂,
src    └──────────────────────┘
typ    └──────────────────────┘
doc    └──────────────────────┘
txt    └──────────────────────┘
par    └──────────────────────┘
pid          └────────────────┘
st   ─────────────────────────┘└─
897    have := add_lt_add
id             └────────┘
src    └──────┘└────────┘
typ    └──────┘└────────┘
doc    └──────┘          
txt    └──────┘          
par    └──────┘          
pid    └───┘└─┘          
st   ─────────────────────
898      (abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1
id                                                          └┘        └┘
src  ───┘               └─┘                                     └┘  └────
typ  ───┘               └─┘                               └┘    └┘└┘└────
doc  ───┘               └─┘                                     └┘  └────
txt  ───┘               └─┘                                     └┘  └────
par  ───┘               └─┘                                     └┘  └────
pid  ───┘               └─┘                                     └┘  └────
st   ────────────────────────────────────────────────────────────────────────
899      (abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1,
id        └────────────┘    └────────────┘  └─────────────┘ └┘ └┘ └┘  └┘
src  ───┘ └────────────┘└─┘ └────────────┘ └─────────────┘      └┘  └──┘
typ  ───┘ └────────────┘└─┘ └────────────┘ └─────────────┘└┘└┘└┘└┘└┘└──┘
doc  ───┘               └─┘                                     └┘  └──┘
txt  ───┘               └─┘                                     └┘  └──┘
par  ───┘               └─┘                                     └┘  └──┘
pid  ───┘               └─┘                                     └┘  └┘└┘
st   ──────────────────────────────────────────────────────────────────────┘└─
900    rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this
id          └────────┘  └───────┘ └┘  └────────────────┘  └───────┘ └┘
src    └───┘└────────┘└┘└───────┘  └┘└────────────────┘└┘└───────┘  └────────┘
typ    └───┘└────────┘└┘└───────┘└┘└┘└────────────────┘└┘└───────┘└┘└────────┘
doc    └───┘          └┘           └┘                  └┘           └────────┘
txt    └───┘          └┘           └┘                  └┘           └────────┘
par    └───┘          └┘           └┘                  └┘           └────────┘
pid       └┘          └┘           └┘                  └┘           └──────┘
st   ────────────────┘└────────────┘└──────────────────┘└────────────┘└───────┘
901  end⟩)
st   └─┘
902  
903  theorem uniform_continuous_dist [uniform_space β] {f g : β → α}
id                                    └───────────┘             
src                                   └───────────┘
typ                                   └───────────┘             
doc                                   └───────────┘
904    (hf : uniform_continuous f) (hg : uniform_continuous g) :
id           └────────────────┘         └────────────────┘ 
src          └────────────────┘          └────────────────┘
typ          └────────────────┘         └────────────────┘ 
905    uniform_continuous (λb, dist (f b) (g b)) :=
id     └────────────────┘     └──┘       
src    └────────────────┘      └──┘
typ    └────────────────┘     └──┘       
906  uniform_continuous_dist'.comp (hf.prod_mk hg)
id   └──────────────────────┘└───┘  └┘└──────┘ └┘
src  └──────────────────────┘└───┘    └──────┘
typ  └──────────────────────┘└───┘  └┘└──────┘ └┘
907  
908  theorem continuous_dist' : continuous (λp:α×α, dist p.1 p.2) :=
id                              └────────┘       └──┘   
src                             └────────┘         └──┘     
typ                             └────────┘       └──┘   
doc                             └────────┘
909  uniform_continuous_dist'.continuous
id   └──────────────────────┘└─────────┘
src  └──────────────────────┘└─────────┘
typ  └──────────────────────┘└─────────┘
910  
911  theorem continuous_dist [topological_space β] {f g : β → α}
id                            └───────────────┘             
src                           └───────────────┘
typ                           └───────────────┘             
doc                           └───────────────┘
912    (hf : continuous f) (hg : continuous g) : continuous (λb, dist (f b) (g b)) :=
id           └────────┘         └────────┘     └────────┘     └──┘       
src          └────────┘          └────────┘      └────────┘      └──┘
typ          └────────┘         └────────┘     └────────┘     └──┘       
doc          └────────┘          └────────┘      └────────┘
913  continuous_dist'.comp (hf.prod_mk hg)
id   └──────────────┘└───┘  └┘└──────┘ └┘
src  └──────────────┘└───┘    └──────┘
typ  └──────────────┘└───┘  └┘└──────┘ └┘
914  
915  theorem tendsto_dist {f g : β → α} {x : filter β} {a b : α}
id                                         └────┘          
src                                          └────┘
typ                                        └────┘          
916    (hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
id           └─────┘              └─────┘     
src          └─────┘                 └─────┘      
typ          └─────┘              └─────┘     
doc          └─────┘                 └─────┘      
917    tendsto (λx, dist (f x) (g x)) x (𝓝 (dist a b)) :=
id     └─────┘     └──┘              └──┘  
src    └─────┘      └──┘                   └──┘
typ    └─────┘     └──┘              └──┘  
doc    └─────┘                           
918  have tendsto (λp:α×α, dist p.1 p.2) (𝓝 (a, b)) (𝓝 (dist a b)),
id        └─────┘       └──┘                └──┘  
src       └─────┘         └──┘                    └──┘
typ       └─────┘       └──┘                └──┘  
doc       └─────┘                                   
919    from continuous_iff_continuous_at.mp continuous_dist' (a, b),
id          └──────────────────────────┘└─┘ └──────────────┘   
src         └──────────────────────────┘└─┘ └──────────────┘ 
typ         └──────────────────────────┘└─┘ └──────────────┘   
920  tendsto.comp (by rw [nhds_prod_eq] at this; exact this) (hf.prod_mk hg)
id   └──────────┘         └──────────┘                 └──┘   └┘└──────┘ └┘
src  └──────────┘     └──┘└──────────┘└───────┘  └────┘         └──────┘
typ  └──────────┘     └──┘└──────────┘└───────┘  └────┘└──┘   └┘└──────┘ └┘
doc                   └──┘            └───────┘  └────┘
txt                   └──┘            └───────┘  └────┘
par                   └──┘            └───────┘  └────┘
pid                     └┘            └──────┘       
st                   └───────────────┘└──────────────────┘
921  
922  lemma nhds_comap_dist (a : α) : (𝓝 (0 : ℝ)).comap (λa', dist a' a) = 𝓝 a :=
id                                           └───┘    └┘  └──┘ └┘     
src                                           └───┘        └──┘        
typ                                          └───┘    └┘  └──┘ └┘     
doc                                            └───┘                     
923  have h₁ : ∀ε, (λa', dist a' a) ⁻¹' ball 0 ε ⊆ ball a ε,
id                  └┘  └──┘ └┘   └─┘ └──┘     └──┘  
src                      └──┘       └─┘ └──┘      └──┘
typ                 └┘  └──┘ └┘   └─┘ └──┘     └──┘  
doc                                 └─┘ └──┘       └──┘
924    by simp [subset_def, real.dist_0_eq_abs],
id              └────────┘  └────────────────┘
src       └────┘└────────┘└┘└────────────────┘
typ       └────┘└────────┘└┘└────────────────┘
doc       └────┘          └┘                  
txt       └────┘          └┘                  
par       └────┘          └┘                  
pid                     └┘                  
st       └────────────────────────────────────┘
925  have h₂ : tendsto (λa', dist a' a) (𝓝 a) (𝓝 (dist a a)),
id             └─────┘   └┘  └──┘ └┘          └──┘  
src            └─────┘       └──┘               └──┘
typ            └─────┘   └┘  └──┘ └┘          └──┘  
doc            └─────┘                        
926    from tendsto_dist tendsto_id tendsto_const_nhds,
id          └──────────┘ └────────┘ └────────────────┘
src         └──────────┘ └────────┘ └────────────────┘
typ         └──────────┘ └────────┘ └────────────────┘
927  le_antisymm
id   └─────────┘
src  └─────────┘
typ  └─────────┘
928    (by simp [h₁, nhds_eq, infi_le_infi, principal_mono,
id               └┘  └─────┘  └──────────┘  └────────────┘
src        └────┘  └┘└─────┘└┘└──────────┘└┘└────────────┘└─
typ        └────┘└┘└┘└─────┘└┘└──────────┘└┘└────────────┘└─
doc        └────┘  └┘       └┘            └┘              └─
txt        └────┘  └┘       └┘            └┘              └─
par        └────┘  └┘       └┘            └┘              └─
pid              └┘       └┘            └┘              └─
st        └─────────────────────────────────────────────────
929        -le_principal_iff, -le_infi_iff])
src  ─────────────────────────────────────┘
typ  ─────────────────────────────────────┘
doc  ─────────────────────────────────────┘
txt  ─────────────────────────────────────┘
par  ─────────────────────────────────────┘
pid  ─────────────────────────────────────┘
st   ─────────────────────────────────────┘
930    (by simpa [map_le_iff_le_comap.symm, tendsto] using h₂)
id                                          └─────┘        └┘
src        └─────┘                        └┘└─────┘└──────┘
typ        └─────┘└──────────────────────┘└┘└─────┘└──────┘└┘
doc        └─────┘                        └┘└─────┘└──────┘
txt        └─────┘                        └┘       └──────┘
par        └─────┘                        └┘       └──────┘
pid                                     └┘       └────┘
st        └─────────────────────────────────────────────────┘
931  
932  lemma tendsto_iff_dist_tendsto_zero {f : β → α} {x : filter β} {a : α} :
id                                                      └────┘        
src                                                       └────┘
typ                                                     └────┘        
933    (tendsto f x (𝓝 a)) ↔ (tendsto (λb, dist (f b) a) x (𝓝 0)) :=
id      └─────┘          └─────┘     └──┘         
src     └─────┘             └─────┘      └──┘             
typ     └─────┘          └─────┘     └──┘         
doc     └─────┘              └─────┘                       
934  by rw [← nhds_comap_dist a, tendsto_comap_iff]
id            └─────────────┘   └───────────────┘
src     └────┘└─────────────┘ └┘└───────────────┘└─
typ     └────┘└─────────────┘└┘└───────────────┘└─
doc     └────┘                └┘                 └─
txt     └────┘                └┘                 └─
par     └────┘                └┘                 └─
pid       └──┘                └┘                 
st     └──────────────────────┘└─────────────────┘
935  
src  
typ  
doc  
txt  
par  
pid  
st   
936  lemma uniform_continuous_nndist' : uniform_continuous (λp:α×α, nndist p.1 p.2) :=
id                                      └────────────────┘       └────┘   
src                                     └────────────────┘         └────┘     
typ                                     └────────────────┘       └────┘   
doc                                                                 └────┘
937  uniform_continuous_subtype_mk uniform_continuous_dist' _
id   └───────────────────────────┘ └──────────────────────┘
src  └───────────────────────────┘ └──────────────────────┘
typ  └───────────────────────────┘ └──────────────────────┘
938  
939  lemma continuous_nndist' : continuous (λp:α×α, nndist p.1 p.2) :=
id                              └────────┘       └────┘   
src                             └────────┘         └────┘     
typ                             └────────┘       └────┘   
doc                             └────────┘          └────┘
940  uniform_continuous_nndist'.continuous
id   └────────────────────────┘└─────────┘
src  └────────────────────────┘└─────────┘
typ  └────────────────────────┘└─────────┘
941  
942  lemma continuous_nndist [topological_space β] {f g : β → α}
id                            └───────────────┘             
src                           └───────────────┘
typ                           └───────────────┘             
doc                           └───────────────┘
943    (hf : continuous f) (hg : continuous g) : continuous (λb, nndist (f b) (g b)) :=
id           └────────┘         └────────┘     └────────┘     └────┘       
src          └────────┘          └────────┘      └────────┘      └────┘
typ          └────────┘         └────────┘     └────────┘     └────┘       
doc          └────────┘          └────────┘      └────────┘      └────┘
944  continuous_nndist'.comp (hf.prod_mk hg)
id   └────────────────┘└───┘  └┘└──────┘ └┘
src  └────────────────┘└───┘    └──────┘
typ  └────────────────┘└───┘  └┘└──────┘ └┘
945  
946  lemma tendsto_nndist' (a b :α) :
id                               
typ                              
947    tendsto (λp:α×α, nndist p.1 p.2) (filter.prod (𝓝 a) (𝓝 b)) (𝓝 (nndist a b)) :=
id     └─────┘       └────┘       └─────────┘             └────┘  
src    └─────┘         └────┘         └─────────┘               └────┘
typ    └─────┘       └────┘       └─────────┘             └────┘  
doc    └─────┘          └────┘           └─────────┘               └────┘
948  by rw [← nhds_prod_eq]; exact continuous_iff_continuous_at.1 continuous_nndist' _
id            └──────────┘         └──────────────────────────┘   └────────────────┘
src     └────┘└──────────┘  └────┘└──────────────────────────┘└─┘└────────────────┘└──
typ     └────┘└──────────┘  └────┘└──────────────────────────┘└─┘└────────────────┘└──
doc     └────┘              └────┘                            └─┘                  └──
txt     └────┘              └────┘                            └─┘                  └──
par     └────┘              └────┘                            └─┘                  └──
pid       └──┘                                               └─┘                  └┘
st     └─────────────────┘└───────────────────────────────────────────────────────────
949  
src  
typ  
doc  
txt  
par  
pid  
st   
950  namespace metric
951  variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
id                                           └─┘
src                                          └─┘
typ                                          └─┘
952  
953  theorem is_closed_ball : is_closed (closed_ball x ε) :=
id                            └───────┘  └─────────┘  
src                           └───────┘  └─────────┘
typ                           └───────┘  └─────────┘  
doc                           └───────┘  └─────────┘
954  is_closed_le (continuous_dist continuous_id continuous_const) continuous_const
id   └──────────┘  └─────────────┘ └───────────┘ └──────────────┘  └──────────────┘
src  └──────────┘  └─────────────┘ └───────────┘ └──────────────┘  └──────────────┘
typ  └──────────┘  └─────────────┘ └───────────┘ └──────────────┘  └──────────────┘
955  
956  /-- ε-characterization of the closure in metric spaces-/
957  theorem mem_closure_iff' {α : Type u} [metric_space α] {s : set α} {a : α} :
id                                          └──────────┘        └─┘        
src                                         └──────────┘         └─┘
typ                                         └──────────┘        └─┘        
doc                                         └──────────┘
958    a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
id       └─────┘            └──┘    
src       └─────┘                └──┘     
typ      └─────┘            └──┘    
doc        └─────┘
959  ⟨begin
st    └─────
960    intros ha ε hε,
src    └────────────┘
typ    └────────────┘
doc    └────────────┘
txt    └────────────┘
par    └────────────┘
pid          └──────┘
st   ───────────────┘└─
961    obtain ⟨b, hb⟩ : (ball a ε ∩ s).nonempty,
id                       └──┘    
src    └───────────────┘ └──┘   └────────┘
typ    └───────────────┘ └──┘└────────┘
doc    └───────────────┘ └──┘    └────────┘
txt    └───────────────┘         └────────┘
par    └───────────────┘         └────────┘
pid          └─────────┘         └───────┘
st   ─────────────────────────────────────────┘└─
962      from mem_closure_iff.1 ha _ is_open_ball (mem_ball_self hε),
id            └─────────────┘   └┘   └──────────┘  └───────────┘ └┘
src      └───┘└─────────────┘└─┘  └─┘└──────────┘ └───────────┘  
typ      └───┘└─────────────┘└─┘└┘└─┘└──────────┘ └───────────┘└┘
doc      └───┘               └─┘  └─┘                            
txt      └───┘               └─┘  └─┘                            
par      └───┘               └─┘  └─┘                            
pid      └───┘               └─┘  └─┘                            
st   ──────────────────────────────────────────────────────────────┘└─
963    simp,
src    └──┘
typ    └──┘
doc    └──┘
txt    └──┘
par    └──┘
st   ─────┘└─
964    exact ⟨b, ⟨hb.2, by have B := hb.1; simpa [mem_ball'] using B⟩⟩
id               └┘                 └┘           └───────┘        
src    └────┘  └┘   └──┘  └────────┘  └┘└┘└─────┘└───────┘└──────┘ └─┘
typ    └────┘ └┘ └┘└──┘  └────────┘└┘└┘└┘└─────┘└───────┘└──────┘└─┘
doc    └────┘  └┘   └──┘  └────────┘  └┘└┘└─────┘         └──────┘ └─┘
txt    └────┘  └┘   └──┘  └────────┘  └┘└┘└─────┘         └──────┘ └─┘
par    └────┘  └┘   └──┘  └────────┘  └┘└┘└─────┘         └──────┘ └─┘
pid           └┘   └──┘  └─────────┘  └─────────┘         └──────┘ └┘
st   ────────────────────┘└────────────────────────────────────────┘└─┘
965  end,
st   └─┘
966  begin
st   └─────
967    intros H,
src    └──────┘
typ    └──────┘
doc    └──────┘
txt    └──────┘
par    └──────┘
pid          └┘
st   ─────────┘└─
968    apply mem_closure_iff.2,
id           └─────────────┘
src    └────┘└─────────────┘└┘
typ    └────┘└─────────────┘└┘
doc    └────┘               └┘
txt    └────┘               └┘
par    └────┘               └┘
pid                        └┘
st   ────────────────────────┘└─
969    intros o ho ao,
src    └────────────┘
typ    └────────────┘
doc    └────────────┘
txt    └────────────┘
par    └────────────┘
pid          └──────┘
st   ───────────────┘└─
970    rcases is_open_iff.1 ho a ao with ⟨ε, ⟨εpos, hε⟩⟩,
id            └─────────┘   └┘  └┘
src    └─────┘└─────────┘└─┘     └───────────────────┘
typ    └─────┘└─────────┘└─┘└┘└┘└───────────────────┘
doc    └─────┘           └─┘     └───────────────────┘
txt    └─────┘           └─┘     └───────────────────┘
par    └─────┘           └─┘     └───────────────────┘
pid                     └─┘     └───────────────────┘
st   ──────────────────────────────────────────────────┘└─
971    rcases H ε εpos with ⟨b, ⟨bs, bdist⟩⟩,
id              └──┘
src    └─────┘      └────────────────────┘
typ    └─────┘└──┘└────────────────────┘
doc    └─────┘      └────────────────────┘
txt    └─────┘      └────────────────────┘
par    └─────┘      └────────────────────┘
pid                └────────────────────┘
st   ──────────────────────────────────────┘└─
972    have B : b ∈ o ∩ s := ⟨hε (by simpa [dist_comm]), bs⟩,
id                        └┘            └───────┘    └┘
src    └───────┘    └──┘      └─────┘└───────┘└─┘  
typ    └───────┘ └──┘ └┘   └─────┘└───────┘└─┘└┘
doc    └───────┘     └──┘      └─────┘         └─┘  
txt    └───────┘     └──┘      └─────┘         └─┘  
par    └───────┘     └──┘      └─────┘         └─┘  
pid    └────┘└─┘     └──┘      └──────┘         └──┘  
st   ──────────────────────────────┘└────────────────┘└────┘└─
973    exact ⟨b, B⟩
id              
src    └────┘  └┘ └┘
typ    └────┘ └┘└┘
doc    └────┘  └┘ └┘
txt    └────┘  └┘ └┘
par    └────┘  └┘ └┘
pid           └┘ 
st   ──────────────┘
974  end⟩
st   └─┘
975  
976  lemma mem_closure_range_iff {α : Type u} [metric_space α] {e : β → α} {a : α} :
id                                             └──────────┘                  
src                                            └──────────┘
typ                                            └──────────┘                  
doc                                            └──────────┘
977    a ∈ closure (range e) ↔ ∀ε>0, ∃ k : β, dist a (e k) < ε :=
id       └─────┘  └───┘               └──┘       
src       └─────┘  └───┘                  └──┘         
typ      └─────┘  └───┘               └──┘       
doc        └─────┘  └───┘
978  iff.intro
id   └───────┘
src  └───────┘
typ  └───────┘
979  ( assume ha ε hε,
id            └┘  └┘
typ           └┘  └┘
980    let ⟨b, ⟨hb, hab⟩⟩ := metric.mem_closure_iff'.1 ha ε hε in
id     └─┘      └┘           └─────────────────────┘  └┘  └┘
src                          └─────────────────────┘
typ    └─┘      └┘           └─────────────────────┘  └┘  └┘
doc                          └─────────────────────┘
981    let ⟨k, hk⟩ := mem_range.1 hb in
id     └─┘           └───────┘
src                   └───────┘
typ    └─┘           └───────┘
982    ⟨k, by { rw hk, exact hab }⟩ )
id                 └┘        └─┘
src             └─┘    └────┘   
typ             └─┘└┘  └────┘└─┘
doc             └─┘    └────┘   
txt             └─┘    └────┘   
par             └─┘    └────┘   
pid                           
st           └──────┘└──────────┘└┘
983  ( assume h, metric.mem_closure_iff'.2 (assume ε hε,
id              └─────────────────────┘           └┘
src              └─────────────────────┘
typ             └─────────────────────┘           └┘
doc              └─────────────────────┘
984    let ⟨k, hk⟩ := h ε hε in
id     └─┘    └┘       └┘
typ    └─┘    └┘       └┘
985    ⟨e k, ⟨mem_range.2 ⟨k, rfl⟩, hk⟩⟩) )
id           └───────┘      └─┘
src           └───────┘      └─┘
typ          └───────┘      └─┘
986  
987  lemma mem_closure_range_iff_nat {α : Type u} [metric_space α] {e : β → α} {a : α} :
id                                                 └──────────┘                  
src                                                └──────────┘
typ                                                └──────────┘                  
doc                                                └──────────┘
988    a ∈ closure (range e) ↔ ∀n : ℕ, ∃ k : β, dist a (e k) < 1 / ((n : ℝ) + 1) :=
id       └─────┘  └───┘                 └──┘                 
src       └─────┘  └───┘                   └──┘                     
typ      └─────┘  └───┘                 └──┘                 
doc        └─────┘  └───┘
989  ⟨assume ha n, mem_closure_range_iff.1 ha (1 / ((n : ℝ) + 1)) nat.one_div_pos_of_nat,
id           └┘   └───────────────────┘  └┘                 └────────────────────┘
src                └───────────────────┘                      └────────────────────┘
typ          └┘   └───────────────────┘  └┘                 └────────────────────┘
990   assume h, mem_closure_range_iff.2 $ assume ε hε,
id             └───────────────────┘            └┘
src             └───────────────────┘
typ            └───────────────────┘            └┘
991    let ⟨n, hn⟩ := exists_nat_one_div_lt hε in
id     └─┘    └┘     └───────────────────┘ └┘
src                   └───────────────────┘
typ    └─┘    └┘     └───────────────────┘ └┘
992    let ⟨k, hk⟩ := h n  in
id     └─┘    └┘     
typ    └─┘    └┘     
993    ⟨k, calc dist a (e k) < 1 / ((n : ℝ) + 1) : hk ... < ε : hn⟩⟩
id              └──┘                                   
src             └──┘                      
typ             └──┘                                   
994  
995  theorem mem_of_closed' {α : Type u} [metric_space α] {s : set α} (hs : is_closed s)
id                                        └──────────┘        └─┘         └───────┘ 
src                                       └──────────┘         └─┘          └───────┘
typ                                       └──────────┘        └─┘         └───────┘ 
doc                                       └──────────┘                      └───────┘
996    {a : α} : a ∈ s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
id                           └──┘    
src                                └──┘     
typ                          └──┘    
997  by simpa only [closure_eq_of_is_closed hs] using @mem_closure_iff' _ _ s a
id                  └─────────────────────┘ └┘         └──────────────┘      
src     └──────────┘└─────────────────────┘  └──────┘ └──────────────┘└───┘  
typ     └──────────┘└─────────────────────┘└┘└──────┘ └──────────────┘└───┘
doc     └──────────┘                         └──────┘ └──────────────┘└───┘  
txt     └──────────┘                         └──────┘                 └───┘  
par     └──────────┘                         └──────┘                 └───┘  
pid          └──┘└┘                         └────┘                 └───┘  
st     └────────────────────────────────────────────────────────────────────────
998  
src  
typ  
doc  
txt  
par  
pid  
st   
999  end metric
1000  
1001  section pi
1002  open finset lattice
1003  variables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
id                              └─────┘        └──────────┘    
src                             └─────┘         └──────────┘
typ                             └─────┘        └──────────┘    
doc                             └─────┘         └──────────┘
1004  
1005  /-- A finite product of metric spaces is a metric space, with the sup distance. -/
1006  instance metric_space_pi : metric_space (Πb, π b) :=
id                              └──────────┘      
src                             └──────────┘
typ                             └──────────┘      
doc                             └──────────┘
1007  begin
st   └─────
1008    /- we construct the instance from the emetric space instance to avoid checking again that the
st   ────────────────────────────────────────────────────────────────────────────────────────────────
1009    uniformity is the same as the product uniformity, but we register nevertheless a nice formula
st   ────────────────────────────────────────────────────────────────────────────────────────────────
1010    for the distance -/
st   ──────────────────────
1011    refine emetric_space.to_metric_space_of_dist
id            └───────────────────────────────────┘
src    └─────┘└───────────────────────────────────┘
typ    └─────┘└───────────────────────────────────┘
doc    └─────┘└───────────────────────────────────┘
txt    └─────┘                                     
par    └─────┘                                     
pid                                               
st   ───────────────────────────────────────────────
1012      (λf g, ((sup univ (λb, nndist (f b) (g b)) : nnreal) : ℝ)) _ _,
id                └─┘ └──┘      └────┘                └────┘    
src  ───┘  └───┘  └─┘└──┘  └─┘└────┘   └┘   └───┘└────┘└──┘└────┘
typ  ───┘  └───┘  └─┘└──┘  └─┘└────┘   └┘   └───┘└────┘└──┘└────┘
doc  ───┘  └───┘  └─┘└──┘  └─┘└────┘   └┘   └───┘└────┘└──┘ └────┘
txt  ───┘  └───┘           └─┘         └┘   └───┘      └──┘ └────┘
par  ───┘  └───┘           └─┘         └┘   └───┘      └──┘ └────┘
pid  ───┘  └───┘           └─┘         └┘   └───┘      └──┘ └────┘
st   ─────────────────────────────────────────────────────────────────┘└─
1013    show ∀ (x y : Π (b : β), π b), edist x y ≠ ⊤,
id                                  └───┘      
src    └───┘ └──────┘ └────┘     └───┘  
typ    └───┘ └──────┘ └────┘   └───┘  
doc    └───┘ └──────┘ └────┘             
txt    └───┘ └──────┘ └────┘             
par    └───┘ └──────┘ └────┘             
pid    └───┘ └──────┘ └────┘             
st   ────────────────────────────────────────────────
1014    { assume x y,
src      └────────┘
typ      └────────┘
doc      └────────┘
txt      └────────┘
par      └────────┘
pid      └────────┘
st   ───┘└────────┘└─
1015      rw ← lt_top_iff_ne_top,
id            └───────────────┘
src      └───┘└───────────────┘
typ      └───┘└───────────────┘
doc      └───┘
txt      └───┘
par      └───┘
pid        └─┘
st   ─────────────────────────┘└─
1016      have : (⊥ : ennreal) < ⊤ := ennreal.coe_lt_top,
id                  └─────┘        └────────────────┘
src      └─────┘ └─┘└─────┘└┘ └──┘└────────────────┘
typ      └─────┘ └─┘└─────┘└┘ └──┘└────────────────┘
doc      └─────┘  └─┘└─────┘└┘  └──┘
txt      └─────┘  └─┘       └┘  └──┘
par      └─────┘  └─┘       └┘  └──┘
pid      └───┘└┘  └─┘       └┘  └──┘
st   ─────────────────────────────────────────────────┘└─
1017      simp [edist, this],
id                    └──┘
src      └────┘     └┘    
typ      └────┘     └┘└──┘
doc      └────┘     └┘    
txt      └────┘     └┘    
par      └────┘     └┘    
pid               └┘    
st   ─────────────────────┘└─
1018      assume b,
src      └──────┘
typ      └──────┘
doc      └──────┘
txt      └──────┘
par      └──────┘
pid      └──────┘
st   ───────────┘└─
1019      rw lt_top_iff_ne_top,
id          └───────────────┘
src      └─┘└───────────────┘
typ      └─┘└───────────────┘
doc      └─┘
txt      └─┘
par      └─┘
pid        
st   ───────────────────────┘└─
1020      exact edist_ne_top (x b) (y b) },
id             └──────────┘        
src      └────┘└──────────┘   └┘   └┘
typ      └────┘└──────────┘  └┘ └┘
doc      └────┘└──────────┘   └┘   └┘
txt      └────┘               └┘   └┘
par      └────┘               └┘   └┘
pid                          └┘   
st   ──────────────────────────────────┘└┘
1021    show ∀ (x y : Π (b : β), π b), ↑(sup univ (λ (b : β), nndist (x b) (y b))) =
id                                                         └────┘               
src    └───┘ └──────┘ └────┘               └────┘ └─┘└────┘   └┘   └──┘
typ    └───┘ └──────┘ └────┘              └────┘ └─┘└────┘   └┘   └──┘
doc    └───┘ └──────┘ └────┘                └────┘ └─┘└────┘   └┘   └──┘ 
txt    └───┘ └──────┘ └────┘                └────┘ └─┘         └┘   └──┘ 
par    └───┘ └──────┘ └────┘                └────┘ └─┘         └┘   └──┘ 
pid    └───┘ └──────┘ └────┘                └────┘ └─┘         └┘   └──┘ 
st   ───────────────────────────────────────────────────────────────────────────────
1022      ennreal.to_real (sup univ (λ (b : β), edist (x b) (y b))),
id       └─────────────┘  └─┘ └──┘            └───┘
src  ───┘└─────────────┘ └─┘└──┘  └────┘ └─┘└───┘   └┘   └─┘
typ  ───┘└─────────────┘ └─┘└──┘  └────┘└─┘└───┘   └┘   └─┘
doc  ───┘└─────────────┘ └─┘└──┘  └────┘ └─┘        └┘   └─┘
txt  ───┘                         └────┘ └─┘        └┘   └─┘
par  ───┘                         └────┘ └─┘        └┘   └─┘
pid  ───┘                         └────┘ └─┘        └┘   └─┘
st   ────────────────────────────────────────────────────────────┘└─
1023    { assume x y,
src      └────────┘
typ      └────────┘
doc      └────────┘
txt      └────────┘
par      └────────┘
pid      └────────┘
st   ─────────────┘└─
1024      have : sup univ (λ (b : β), edist (x b) (y b)) = ↑(sup univ (λ (b : β), nndist (x b) (y b))),
id                                   └───┘                  └─┘ └──┘            └────┘       
src      └─────┘         └────┘ └─┘└───┘   └┘   └─┘   └─┘└──┘  └────┘ └─┘└────┘   └┘   └─┘
typ      └─────┘         └────┘ └─┘└───┘   └┘   └─┘   └─┘└──┘  └────┘└─┘└────┘  └┘  └─┘
doc      └─────┘         └────┘ └─┘        └┘   └─┘   └─┘└──┘  └────┘ └─┘└────┘   └┘   └─┘
txt      └─────┘         └────┘ └─┘        └┘   └─┘            └────┘ └─┘         └┘   └─┘
par      └─────┘         └────┘ └─┘        └┘   └─┘            └────┘ └─┘         └┘   └─┘
pid      └───┘└┘         └────┘ └─┘        └┘   └─┘            └────┘ └─┘         └┘   └─┘
st   ───────────────────────────────────────────────────────────────────────────────────────────────┘└─
1025      { simp [edist_nndist],
id               └──────────┘
src        └────┘└──────────┘
typ        └────┘└──────────┘
doc        └────┘└──────────┘
txt        └────┘            
par        └────┘            
pid                        
st   ─────┘└─────────────────┘└─
1026        refine eq.symm (comp_sup_eq_sup_comp _ _ _),
id                └─────┘  └──────────────────┘
src        └─────┘└─────┘ └──────────────────┘└─────┘
typ        └─────┘└─────┘ └──────────────────┘└─────┘
doc        └─────┘                            └─────┘
txt        └─────┘                            └─────┘
par        └─────┘                            └─────┘
pid                                          └─────┘
st   ────────────────────────────────────────────────┘└─
1027        exact (assume x y h, ennreal.coe_le_coe.2 h), refl },
id                              └────────────────┘
src        └────┘       └──────┘└────────────────┘└─┘   └───┘
typ        └────┘       └──────┘└────────────────┘└─┘   └───┘
doc        └────┘       └──────┘                  └─┘   └───┘
txt        └────┘       └──────┘                  └─┘   └───┘
par        └────┘       └──────┘                  └─┘   └───┘
pid                    └──────┘                  └─┘       
st   ─────────────────────────────────────────────────┘└─────┘└┘
1028      rw this,
id          └──┘
src      └─┘
typ      └─┘└──┘
doc      └─┘
txt      └─┘
par      └─┘
pid        
st   ──────────┘└─
1029      refl }
src      └───┘
typ      └───┘
doc      └───┘
txt      └───┘
par      └───┘
pid          
st   ────────┘└─
1030  end
st   ──┘
1031  
1032  lemma dist_pi_def (f g : Πb, π b) :
id                                
typ                               
1033    dist f g = (sup univ (λb, nndist (f b) (g b)) : nnreal) := rfl
id     └──┘     └─┘ └──┘     └────┘            └────┘     └─┘
src    └──┘       └─┘ └──┘      └────┘                └────┘     └─┘
typ    └──┘     └─┘ └──┘     └────┘            └────┘     └─┘
doc                └─┘ └──┘      └────┘                └────┘
1034  
1035  lemma dist_pi_lt_iff {f g : Πb, π b} {r : ℝ} (hr : 0 < r) :
id                                                     
src                                                      
typ                                                    
1036    dist f g < r ↔ ∀b, dist (f b) (g b) < r :=
id     └──┘         └──┘          
src    └──┘             └──┘             
typ    └──┘         └──┘          
1037  begin
st   └─────
1038    lift r to nnreal using le_of_lt hr,
id              └────┘       └──────┘ └┘
src    └───┘ └──┘└────┘└─────┘└──────┘
typ    └───┘└──┘└────┘└─────┘└──────┘└┘
doc    └───┘ └──┘└────┘└─────┘        
txt    └───┘ └──┘      └─────┘        
par    └───┘ └──┘      └─────┘        
pid         └──┘      └─────┘        
st   ───────────────────────────────────┘└─
1039    rw_mod_cast [dist_pi_def, finset.sup_lt_iff],
id                  └─────────┘  └───────────────┘
src    └───────────┘└─────────┘└┘└───────────────┘
typ    └───────────┘└─────────┘└┘└───────────────┘
doc    └───────────┘           └┘                 
txt    └───────────┘           └┘                 
par    └───────────┘           └┘                 
pid               └┘           └┘                 
st   ─────────────────────────┘└─────────────────┘ └─
1040    { simp [nndist], refl },
id             └────┘
src      └────┘└────┘  └───┘
typ      └────┘└────┘  └───┘
doc      └────┘└────┘  └───┘
txt      └────┘        └───┘
par      └────┘        └───┘
pid                      
st   ───┘└───────────┘└─────┘└┘
1041    { exact hr }
id             └┘
src      └────┘  
typ      └────┘└┘
doc      └────┘  
txt      └────┘  
par      └────┘  
pid             
st   ────────────┘└─
1042  end
st   ──┘
1043  
1044  lemma dist_pi_le_iff {f g : Πb, π b} {r : ℝ} (hr : 0 ≤ r) :
id                                                     
src                                                      
typ                                                    
1045    dist f g ≤ r ↔ ∀b, dist (f b) (g b) ≤ r :=
id     └──┘         └──┘          
src    └──┘             └──┘             
typ    └──┘         └──┘          
1046  begin
st   └─────
1047    lift r to nnreal using hr,
id              └────┘       └┘
src    └───┘ └──┘└────┘└─────┘
typ    └───┘└──┘└────┘└─────┘└┘
doc    └───┘ └──┘└────┘└─────┘
txt    └───┘ └──┘      └─────┘
par    └───┘ └──┘      └─────┘
pid         └──┘      └─────┘
st   ──────────────────────────┘└─
1048    rw_mod_cast [dist_pi_def, finset.sup_le_iff],
id                  └─────────┘  └───────────────┘
src    └───────────┘└─────────┘└┘└───────────────┘
typ    └───────────┘└─────────┘└┘└───────────────┘
doc    └───────────┘           └┘                 
txt    └───────────┘           └┘                 
par    └───────────┘           └┘                 
pid               └┘           └┘                 
st   ─────────────────────────┘└─────────────────┘ └─
1049    simp [nndist],
id           └────┘
src    └────┘└────┘
typ    └────┘└────┘
doc    └────┘└────┘
txt    └────┘      
par    └────┘      
pid              
st   ──────────────┘└─
1050    refl
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
pid        
st   ──────┘
1051  end
st   └─┘
1052  
1053  /-- An open ball in a product space is a product of open balls. The assumption `0 < r`
1054  is necessary for the case of the empty product. -/
1055  lemma ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 < r) :
id                                            
src                                             
typ                                           
1056    ball x r = { y | ∀b, y b ∈ ball (x b) r } :=
id     └──┘              └──┘     
src    └──┘                    └──┘
typ    └──┘              └──┘     
doc    └──┘                       └──┘
1057  by { ext p, simp [dist_pi_lt_iff hr] }
id                     └────────────┘ └┘
src       └───┘  └────┘└────────────┘  └┘
typ       └───┘  └────┘└────────────┘└┘└┘
doc       └───┘  └────┘                └┘
txt       └───┘  └────┘                └┘
par       └───┘  └────┘                └┘
pid          └┘                      
st     └──────┘└─────────────────────────┘└┘
1058  
1059  /-- A closed ball in a product space is a product of closed balls. The assumption `0 ≤ r`
1060  is necessary for the case of the empty product. -/
1061  lemma closed_ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 ≤ r) :
id                                                   
src                                                    
typ                                                  
1062    closed_ball x r = { y | ∀b, y b ∈ closed_ball (x b) r } :=
id     └─────────┘              └─────────┘     
src    └─────────┘                    └─────────┘
typ    └─────────┘              └─────────┘     
doc    └─────────┘                       └─────────┘
1063  by { ext p, simp [dist_pi_le_iff hr] }
id                     └────────────┘ └┘
src       └───┘  └────┘└────────────┘  └┘
typ       └───┘  └────┘└────────────┘└┘└┘
doc       └───┘  └────┘                └┘
txt       └───┘  └────┘                └┘
par       └───┘  └────┘                └┘
pid          └┘                      
st     └──────┘└─────────────────────────┘└┘
1064  
1065  end pi
1066  
1067  section compact
1068  
1069  /-- Any compact set in a metric space can be covered by finitely many balls of a given positive
1070  radius -/
1071  lemma finite_cover_balls_of_compact {α : Type u} [metric_space α] {s : set α}
id                                                     └──────────┘        └─┘ 
src                                                    └──────────┘         └─┘
typ                                                    └──────────┘        └─┘ 
doc                                                    └──────────┘
1072    (hs : compact s) {e : ℝ} (he : 0 < e) :
id           └─────┘                   
src          └─────┘                   
typ          └─────┘                   
doc          └─────┘
1073    ∃t ⊆ s, finite t ∧ s ⊆ ⋃x∈t, ball x e :=
id         └────┘       └──┘  
src          └────┘           └──┘
typ        └────┘       └──┘  
doc            └────┘             └──┘
1074  begin
st   └─────
1075    apply hs.elim_finite_subcover_image,
src    └────┘
typ    └────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ────────────────────────────────────┘└─
1076    { simp [is_open_ball] },
id             └──────────┘
src      └────┘└──────────┘└┘
typ      └────┘└──────────┘└┘
doc      └────┘            └┘
txt      └────┘            └┘
par      └────┘            └┘
pid                      
st   ───┘└──────────────────┘└┘
1077    { intros x xs,
src      └─────────┘
typ      └─────────┘
doc      └─────────┘
txt      └─────────┘
par      └─────────┘
pid            └───┘
st   ──────────────┘└─
1078      simp,
src      └──┘
typ      └──┘
doc      └──┘
txt      └──┘
par      └──┘
st   ───────┘└─
1079      exact ⟨x, ⟨xs, by simpa⟩⟩ }
id                 └┘
src      └────┘  └┘   └┘  └───┘└─┘
typ      └────┘ └┘ └┘└┘  └───┘└─┘
doc      └────┘  └┘   └┘  └───┘└─┘
txt      └────┘  └┘   └┘  └───┘└─┘
par      └────┘  └┘   └┘  └───┘└─┘
pid             └┘   └┘  └──────┘
st   ────────────────────┘└────┘└─┘└─
1080  end
st   ──┘
1081  
1082  alias finite_cover_balls_of_compact ← compact.finite_cover_balls
1083  
1084  end compact
1085  
1086  section proper_space
1087  open metric
1088  
1089  /-- A metric space is proper if all closed balls are compact. -/
1090  class proper_space (α : Type u) [metric_space α] : Prop :=
id                           └──┘     └──────────┘ 
src                                   └──────────┘
typ                          └──┘     └──────────┘ 
doc                                   └──────────┘
1091  (compact_ball : ∀x:α, ∀r, compact (closed_ball x r))
id                          └─────┘  └─────────┘  
src                            └─────┘  └─────────┘
typ                         └─────┘  └─────────┘  
doc                            └─────┘  └─────────┘
1092  
1093  /-- If all closed balls of large enough radius are compact, then the space is proper. Especially
1094  useful when the lower bound for the radius is 0. -/
1095  lemma proper_space_of_compact_closed_ball_of_le
1096    (R : ℝ) (h : ∀x:α, ∀r, R ≤ r → compact (closed_ball x r)) :
id                              └─────┘  └─────────┘  
src                                 └─────┘  └─────────┘
typ                             └─────┘  └─────────┘  
doc                                   └─────┘  └─────────┘
1097    proper_space α :=
id     └──────────┘ 
src    └──────────┘
typ    └──────────┘ 
doc    └──────────┘
1098  ⟨begin
st    └─────
1099    assume x r,
src    └────────┘
typ    └────────┘
doc    └────────┘
txt    └────────┘
par    └────────┘
pid    └────────┘
st   ───────────┘└─
1100    by_cases hr : R ≤ r,
id                     
src    └───────┘  └─┘ 
typ    └───────┘  └─┘
doc    └───────┘  └─┘  
txt    └───────┘  └─┘  
par    └───────┘  └─┘  
pid              └─┘  
st   ────────────────────┘└─
1101    { exact h x r hr },
id                └┘
src      └────┘     
typ      └────┘└┘
doc      └────┘     
txt      └────┘     
par      └────┘     
pid                
st   ───┘└─────────────┘└┘
1102    { have : closed_ball x r = closed_ball x R ∩ closed_ball x r,
id                                               └─────────┘  
src      └─────┘                          └─────────┘ 
typ      └─────┘                         └─────────┘
doc      └─────┘                            └─────────┘ 
txt      └─────┘                                        
par      └─────┘                                        
pid      └───┘└┘                                        
st   ─────────────────────────────────────────────────────────────┘└─
1103      { symmetry,
src        └──────┘
typ        └──────┘
doc        └──────┘
txt        └──────┘
par        └──────┘
st   ─────┘└──────┘└─
1104        apply inter_eq_self_of_subset_right,
id               └───────────────────────────┘
src        └────┘└───────────────────────────┘
typ        └────┘└───────────────────────────┘
doc        └────┘
txt        └────┘
par        └────┘
pid             
st   ────────────────────────────────────────┘└─
1105        exact closed_ball_subset_closed_ball (le_of_lt (not_le.1 hr)) },
id               └────────────────────────────┘  └──────┘  └────┘   └┘
src        └────┘└────────────────────────────┘ └──────┘ └────┘└─┘  └─┘
typ        └────┘└────────────────────────────┘ └──────┘ └────┘└─┘└┘└─┘
doc        └────┘                                              └─┘  └─┘
txt        └────┘                                              └─┘  └─┘
par        └────┘                                              └─┘  └─┘
pid                                                           └─┘  └┘
st   ───────────────────────────────────────────────────────────────────┘└┘
1106      rw this,
id          └──┘
src      └─┘
typ      └─┘└──┘
doc      └─┘
txt      └─┘
par      └─┘
pid        
st   ──────────┘└─
1107      exact (h x R (le_refl _)).inter_right is_closed_ball }
id                  └─────┘                 └────────────┘
src      └────┘     └─────┘└───────────────┘└────────────┘
typ      └────┘  └─────┘└───────────────┘└────────────┘
doc      └────┘            └───────────────┘              
txt      └────┘            └───────────────┘              
par      └────┘            └───────────────┘              
pid                       └───────────────┘              
st   ────────────────────────────────────────────────────────┘└─
1108  end⟩
st   ──┘
1109  
1110  /- A compact metric space is proper -/
1111  @[priority 100] -- see Note [lower instance priority]
1112  instance proper_of_compact [compact_space α] : proper_space α :=
id                               └───────────┘     └──────────┘ 
src                              └───────────┘      └──────────┘
typ                              └───────────┘     └──────────┘ 
doc                              └───────────┘      └──────────┘
1113  ⟨assume x r, compact_of_is_closed_subset compact_univ is_closed_ball (subset_univ _)⟩
id              └─────────────────────────┘ └──────────┘ └────────────┘  └─────────┘
src               └─────────────────────────┘ └──────────┘ └────────────┘  └─────────┘
typ             └─────────────────────────┘ └──────────┘ └────────────┘  └─────────┘
1114  
1115  /-- A proper space is locally compact -/
1116  @[priority 100] -- see Note [lower instance priority]
1117  instance locally_compact_of_proper [proper_space α] :
id                                       └──────────┘ 
src                                      └──────────┘
typ                                      └──────────┘ 
doc                                      └──────────┘
1118    locally_compact_space α :=
id     └───────────────────┘ 
src    └───────────────────┘
typ    └───────────────────┘ 
doc    └───────────────────┘
1119  begin
st   └─────
1120    apply locally_compact_of_compact_nhds,
id           └─────────────────────────────┘
src    └────┘└─────────────────────────────┘
typ    └────┘└─────────────────────────────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ──────────────────────────────────────┘└─
1121    intros x,
src    └──────┘
typ    └──────┘
doc    └──────┘
txt    └──────┘
par    └──────┘
pid          └┘
st   ─────────┘└─
1122    existsi closed_ball x 1,
id             └─────────┘ 
src    └──────┘└─────────┘ └┘
typ    └──────┘└─────────┘└┘
doc    └──────┘└─────────┘ └┘
txt    └──────┘            └┘
par    └──────┘            └┘
pid                       
st   ────────────────────────┘└─
1123    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
1124    { apply mem_nhds_iff.2,
id             └──────────┘
src      └────┘└──────────┘└┘
typ      └────┘└──────────┘└┘
doc      └────┘            └┘
txt      └────┘            └┘
par      └────┘            └┘
pid                       └┘
st   ───┘└──────────────────┘└─
1125      existsi (1 : ℝ),
src      └──────┘ └──┘ 
typ      └──────┘ └──┘ 
doc      └──────┘ └──┘ 
txt      └──────┘ └──┘ 
par      └──────┘ └──┘ 
pid              └──┘ 
st   ──────────────────┘└─
1126      simp,
src      └──┘
typ      └──┘
doc      └──┘
txt      └──┘
par      └──┘
st   ───────┘└─
1127      exact ⟨zero_lt_one, ball_subset_closed_ball⟩ },
id              └─────────┘  └─────────────────────┘
src      └────┘ └─────────┘└┘└─────────────────────┘└┘
typ      └────┘ └─────────┘└┘└─────────────────────┘└┘
doc      └────┘            └┘                       └┘
txt      └────┘            └┘                       └┘
par      └────┘            └┘                       └┘
pid                       └┘                       
st   ────────────────────────────────────────────────┘└┘
1128    { apply proper_space.compact_ball }
id             └───────────────────────┘
src      └────┘└───────────────────────┘
typ      └────┘└───────────────────────┘
doc      └────┘                         
txt      └────┘                         
par      └────┘                         
pid                                    
st   ───────────────────────────────────┘└─
1129  end
st   ──┘
1130  
1131  /-- A proper space is complete -/
1132  @[priority 100] -- see Note [lower instance priority]
1133  instance complete_of_proper [proper_space α] : complete_space α :=
id                                └──────────┘     └────────────┘ 
src                               └──────────┘      └────────────┘
typ                               └──────────┘     └────────────┘ 
doc                               └──────────┘      └────────────┘
1134  ⟨begin
st    └─────
1135    intros f hf,
src    └─────────┘
typ    └─────────┘
doc    └─────────┘
txt    └─────────┘
par    └─────────┘
pid          └───┘
st   ────────────┘└─
1136    /- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
st   ────────────────────────────────────────────────────────────────────────────────────────────
1137    ball (therefore compact by properness) where it is nontrivial. -/
st   ────────────────────────────────────────────────────────────────────
1138    have A : ∃ t ∈ f, ∀ x y ∈ t, dist x y < 1 := (metric.cauchy_iff.1 hf).2 1 zero_lt_one,
id                               └──┘            └───────────────┘   └┘      └─────────┘
src    └───────┘└───┘  └─────┘  └──┘  └────┘ └───────────────┘└─┘  └────┘└─────────┘
typ    └───────┘└───┘ └─────┘  └──┘  └────┘ └───────────────┘└─┘└┘└────┘└─────────┘
doc    └───────┘ └───┘   └─────┘         └────┘                  └─┘  └────┘
txt    └───────┘ └───┘   └─────┘         └────┘                  └─┘  └────┘
par    └───────┘ └───┘   └─────┘         └────┘                  └─┘  └────┘
pid    └────┘└─┘ └───┘   └─────┘         └───┘                  └─┘  └────┘
st   ──────────────────────────────────────────────────────────────────────────────────────┘└─
1139    rcases A with ⟨t, ⟨t_fset, ht⟩⟩,
id            
src    └─────┘ └─────────────────────┘
typ    └─────┘└─────────────────────┘
doc    └─────┘ └─────────────────────┘
txt    └─────┘ └─────────────────────┘
par    └─────┘ └─────────────────────┘
pid           └─────────────────────┘
st   ────────────────────────────────┘└─
1140    rcases nonempty_of_mem_sets hf.1 t_fset with ⟨x, xt⟩,
id            └──────────────────┘ └┘   └────┘
src    └─────┘└──────────────────┘  └─┘      └───────────┘
typ    └─────┘└──────────────────┘└┘└─┘└────┘└───────────┘
doc    └─────┘                      └─┘      └───────────┘
txt    └─────┘                      └─┘      └───────────┘
par    └─────┘                      └─┘      └───────────┘
pid                                └─┘      └───────────┘
st   ─────────────────────────────────────────────────────┘└─
1141    have : t ⊆ closed_ball x 1 := by intros y yt; simp [dist_comm]; apply le_of_lt (ht x y xt yt),
id              └─────────┘                             └───────┘         └──────┘  └┘   └┘ └┘
src    └─────┘ └─────────┘ └────┘  └─────────┘└┘└────┘└───────┘└┘└────┘└──────┘         
typ    └─────┘└─────────┘└────┘  └─────────┘└┘└────┘└───────┘└┘└────┘└──────┘ └┘└┘└┘
doc    └─────┘  └─────────┘ └────┘  └─────────┘└┘└────┘         └┘└────┘                 
txt    └─────┘              └────┘  └─────────┘└┘└────┘         └┘└────┘                 
par    └─────┘              └────┘  └─────────┘└┘└────┘         └┘└────┘                 
pid    └───┘└┘              └───┘  └──────────────────┘         └───────┘                 
st   ─────────────────────────────────┘└───────────────────────────────────────────────────────────┘└─
1142    have : closed_ball x 1 ∈ f := f.sets_of_superset t_fset this,
id            └─────────┘          └────────────────┘ └────┘ └──┘
src    └─────┘└─────────┘ └─┘  └──┘└────────────────┘      
typ    └─────┘└─────────┘└─┘ └──┘└────────────────┘└────┘└──┘
doc    └─────┘└─────────┘ └─┘  └──┘                        
txt    └─────┘            └─┘  └──┘                        
par    └─────┘            └─┘  └──┘                        
pid    └───┘└┘            └─┘  └──┘                        
st   ─────────────────────────────────────────────────────────────┘└─
1143    rcases (compact_iff_totally_bounded_complete.1 (proper_space.compact_ball x 1)).2 f hf (le_principal_iff.2 this)
id             └──────────────────────────────────┘    └───────────────────────┘         └┘  └──────────────┘   └──┘
src    └─────┘ └──────────────────────────────────┘└─┘ └───────────────────────┘ └─────┘    └──────────────┘└─┘    └─
typ    └─────┘ └──────────────────────────────────┘└─┘ └───────────────────────┘└─────┘└┘ └──────────────┘└─┘└──┘└─
doc    └─────┘                                     └─┘                           └─────┘                    └─┘    └─
txt    └─────┘                                     └─┘                           └─────┘                    └─┘    └─
par    └─────┘                                     └─┘                           └─────┘                    └─┘    └─
pid                                               └─┘                           └─────┘                    └─┘    └─
st   ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1144      with ⟨y, _, hy⟩,
src  ──────────────────┘
typ  ──────────────────┘
doc  ──────────────────┘
txt  ──────────────────┘
par  ──────────────────┘
pid  ──────────────────┘
st   ──────────────────┘└─
1145    exact ⟨y, hy⟩
id              └┘
src    └────┘  └┘  └┘
typ    └────┘ └┘└┘└┘
doc    └────┘  └┘  └┘
txt    └────┘  └┘  └┘
par    └────┘  └┘  └┘
pid           └┘  
st   ───────────────┘
1146  end⟩
st   └─┘
1147  
1148  /-- A proper metric space is separable, and therefore second countable. Indeed, any ball is
1149  compact, and therefore admits a countable dense subset. Taking a countable union over the balls
1150  centered at a fixed point and with integer radius, one obtains a countable set which is
1151  dense in the whole space. -/
1152  @[priority 100] -- see Note [lower instance priority]
1153  instance second_countable_of_proper [proper_space α] :
id                                        └──────────┘ 
src                                       └──────────┘
typ                                       └──────────┘ 
doc                                       └──────────┘
1154    second_countable_topology α :=
id     └───────────────────────┘ 
src    └───────────────────────┘
typ    └───────────────────────┘ 
doc    └───────────────────────┘
1155  begin
st   └─────
1156    /- We show that the space admits a countable dense subset. The case where the space is empty
st   ───────────────────────────────────────────────────────────────────────────────────────────────
1157    is special, and trivial. -/
st   ──────────────────────────────
1158    have A : (univ : set α) = ∅ → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=
id                      └─┘                    └───────┘    └─────┘      └──┘   └─┘ 
src    └───────┘     └─┘    └┘ └───┘    └───────┘ └─────┘   └──┘└─┘└─┘ └────
typ    └───────┘     └─┘└─┘ └┘ └───┘    └───────┘ └─────┘   └──┘└─┘└─┘└────
doc    └───────┘     └─┘    └┘    └───┘     └───────┘  └─────┘       └─┘    └────
txt    └───────┘     └─┘    └┘    └───┘                              └─┘    └────
par    └───────┘     └─┘    └┘    └───┘                              └─┘    └────
pid    └────┘└─┘     └─┘    └┘    └───┘                              └─┘    └───
st   ──────────────────────────────────────────────────────────────────────────────────────────
1159      assume H, ⟨∅, ⟨by simp, by simp; exact H.symm⟩⟩,
id                                              └────┘
src  ───┘      └──┘  └┘   └──┘└┘  └──┘└┘└────┘└────┘└┘
typ  ───┘      └──┘  └┘   └──┘└┘  └──┘└┘└────┘└────┘└┘
doc  ───┘      └──┘  └┘   └──┘└┘  └──┘└┘└────┘      └┘
txt  ───┘      └──┘  └┘   └──┘└┘  └──┘└┘└────┘      └┘
par  ───┘      └──┘  └┘   └──┘└┘  └──┘└┘└────┘      └┘
pid  ───┘      └──┘  └┘   └─────┘  └───────────┘      └┘
st   ────────────────────┘└───┘└──┘└─────────────────┘└┘└─
1160    have B : (univ : set α).nonempty → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=
id                                                    └───────┘     └─────┘      └──┘   └─┘ 
src    └───────┘     └─┘    └─────────┘ └───┘    └───────┘  └─────┘   └──┘└─┘└─┘ └────
typ    └───────┘     └─┘    └─────────┘ └───┘    └───────┘  └─────┘   └──┘└─┘└─┘└────
doc    └───────┘     └─┘    └─────────┘  └───┘     └───────┘  └─────┘       └─┘    └────
txt    └───────┘     └─┘    └─────────┘  └───┘                              └─┘    └────
par    └───────┘     └─┘    └─────────┘  └───┘                              └─┘    └────
pid    └────┘└─┘     └─┘    └─────────┘  └───┘                              └─┘    └───
st   ───────────────────────────────────────────────────────────────────────────────────────────────
1161    begin
src  ─┘     
typ  ─┘     
doc  ─┘     
txt  ─┘     
par  ─┘     
pid  ─┘     
st   ─┘└─────
1162      /- When the space is not empty, we take a point `x` in the space, and then a countable set
src  ───────────────────────────────────────────────────────────────────────────────────────────────
typ  ───────────────────────────────────────────────────────────────────────────────────────────────
doc  ───────────────────────────────────────────────────────────────────────────────────────────────
txt  ───────────────────────────────────────────────────────────────────────────────────────────────
par  ───────────────────────────────────────────────────────────────────────────────────────────────
pid  ───────────────────────────────────────────────────────────────────────────────────────────────
st   ───────────────────────────────────────────────────────────────────────────────────────────────
1163      `T r` which is dense in the closed ball `closed_ball x r` for each `r`. Then the set
src  ─────────────────────────────────────────────────────────────────────────────────────────
typ  ─────────────────────────────────────────────────────────────────────────────────────────
doc  ─────────────────────────────────────────────────────────────────────────────────────────
txt  ─────────────────────────────────────────────────────────────────────────────────────────
par  ─────────────────────────────────────────────────────────────────────────────────────────
pid  ─────────────────────────────────────────────────────────────────────────────────────────
st   ─────────────────────────────────────────────────────────────────────────────────────────
1164      `t = ⋃ T n` (where the union is over all integers `n`) is countable, as a countable union
src  ──────────────────────────────────────────────────────────────────────────────────────────────
typ  ──────────────────────────────────────────────────────────────────────────────────────────────
doc  ──────────────────────────────────────────────────────────────────────────────────────────────
txt  ──────────────────────────────────────────────────────────────────────────────────────────────
par  ──────────────────────────────────────────────────────────────────────────────────────────────
pid  ──────────────────────────────────────────────────────────────────────────────────────────────
st   ──────────────────────────────────────────────────────────────────────────────────────────────
1165      of countable sets, and dense in the space by construction. -/
src  ──────────────────────────────────────────────────────────────────
typ  ──────────────────────────────────────────────────────────────────
doc  ──────────────────────────────────────────────────────────────────
txt  ──────────────────────────────────────────────────────────────────
par  ──────────────────────────────────────────────────────────────────
pid  ──────────────────────────────────────────────────────────────────
st   ──────────────────────────────────────────────────────────────────
1166      rintros ⟨x, x_univ⟩,
src  ───┘└─────────────────┘└─
typ  ───┘└─────────────────┘└─
doc  ───┘└─────────────────┘└─
txt  ───┘└─────────────────┘└─
par  ───┘└─────────────────┘└─
pid  ─────────────────────────
st   ──────────────────────┘└─
1167      choose T a using show ∀ (r:ℝ), ∃ t ⊆ closed_ball x r, (countable (t : set α) ∧ closed_ball x r = closure t),
id                                                           └───────┘     └─┘     └─────────┘      └─────┘
src  ───┘└───────────────┘     └──┘ └───┘              └───────┘  └─┘└─┘ └┘ └─────────┘   └─────┘ └──
typ  ───┘└───────────────┘     └──┘ └───┘              └───────┘ └─┘└─┘└┘ └─────────┘  └─────┘ └──
doc  ───┘└───────────────┘     └──┘   └───┘               └───────┘  └─┘    └┘ └─────────┘   └─────┘ └──
txt  ───┘└───────────────┘     └──┘   └───┘                          └─┘    └┘                       └──
par  ───┘└───────────────┘     └──┘   └───┘                          └─┘    └┘                       └──
pid  ────────────────────┘     └──┘   └───┘                          └─┘    └┘                       └──
st   ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1168        from assume r, emetric.countable_closure_of_compact (proper_space.compact_ball _ _),
id                        └──────────────────────────────────┘  └───────────────────────┘
src  ──────────┘      └──┘└──────────────────────────────────┘ └───────────────────────┘└───┘└─
typ  ──────────┘      └──┘└──────────────────────────────────┘ └───────────────────────┘└───┘└─
doc  ──────────┘      └──┘└──────────────────────────────────┘                          └───┘└─
txt  ──────────┘      └──┘                                                              └───┘└─
par  ──────────┘      └──┘                                                              └───┘└─
pid  ──────────┘      └──┘                                                              └──────
st   ────────────────────────────────────────────────────────────────────────────────────────┘└─
1169      let t := (⋃n:ℕ, T (n : ℝ)),
id                     
src  ───┘└───────┘ └┘    └─┘ └┘└─
typ  ────────────┘ └┘   └─┘ └───
doc  ───┘└───────┘ └┘    └─┘ └┘└─
txt  ───┘└───────┘  └┘     └─┘ └┘└─
par  ────────────┘  └┘     └─┘ └───
pid  ────────────┘  └┘     └─┘ └───
st   ─────────────────────────────┘└─
1170      have T₁ : countable t := by finish [countable_Union],
id                 └───────┘                └─────────────┘
src  ─────────────┘└───────┘ └──┘  └──────┘└─────────────┘└─
typ  ─────────────┘└───────┘└──┘  └──────┘└─────────────┘└─
doc  ─────────────┘└───────┘ └──┘  └──────┘               └─
txt  ─────────────┘          └──┘  └──────┘               └─
par  ─────────────┘          └──┘  └──────┘               └─
pid  ─────────────┘          └──┘  └───────┘               └──
st   ──────────────────────────────┘└───────────────────────┘└─
1171      have T₂ : closure t ⊆ univ := by simp,
id                 └─────┘    └──┘
src  ─────────────┘└─────┘  └──┘└──┘  └──┘└─
typ  ─────────────┘└─────┘ └──┘└──┘  └──┘└─
doc  ─────────────┘└─────┘      └──┘  └──┘└─
txt  ─────────────┘             └──┘  └──┘└─
par  ─────────────┘             └──┘  └──┘└─
pid  ─────────────┘             └──┘  └──────
st   ───────────────────────────────────┘└───┘└─
1172      have T₃ : univ ⊆ closure t :=
id                 └──┘   └─────┘ 
src  ─────────────┘└──┘ └─────┘ └───
typ  ─────────────┘└──┘ └─────┘└───
doc  ─────────────┘     └─────┘ └───
txt  ─────────────┘             └───
par  ─────────────┘             └───
pid  ─────────────┘             └───
st   ──────────────────────────────────
1173      begin
src  ───┘     
typ  ───┘     
doc  ───┘     
txt  ───┘     
par  ───┘     
pid  ───┘     
st   ───┘└─────
1174        intros y y_univ,
src  ─────┘└─────────────┘└─
typ  ─────┘└─────────────┘└─
doc  ─────┘└─────────────┘└─
txt  ─────┘└─────────────┘└─
par  ─────┘└─────────────┘└─
pid  ───────────────────────
st   ────────────────────┘└─
1175        rcases exists_nat_gt (dist y x) with ⟨n, n_large⟩,
id                └───────────┘  └──┘  
src  ─────┘└─────┘└───────────┘ └──┘  └─────────────────┘└─
typ  ─────┘└─────┘└───────────┘ └──┘└─────────────────┘└─
doc  ─────┘└─────┘                    └─────────────────┘└─
txt  ─────┘└─────┘                    └─────────────────┘└─
par  ─────┘└─────┘                    └─────────────────┘└─
pid  ────────────┘                    └────────────────────
st   ──────────────────────────────────────────────────────┘└─
1176        have h : y ∈ closed_ball x (n : ℝ) := by simp; apply le_of_lt n_large,
id                    └─────────┘                           └──────┘ └─────┘
src  ──────────────┘ └─────────┘   └─┘ └───┘  └──┘└┘└────┘└──────┘       └─
typ  ──────────────┘└─────────┘ └─┘ └───┘  └──┘└┘└────┘└──────┘└─────┘└─
doc  ──────────────┘  └─────────┘   └─┘ └───┘  └──┘└┘└────┘               └─
txt  ──────────────┘                └─┘ └───┘  └──┘└┘└────┘               └─
par  ──────────────┘                └─┘ └───┘  └──┘└┘└────┘               └─
pid  ──────────────┘                └─┘ └───┘  └───────────┘               └─
st   ─────────────────────────────────────────────┘└───────────────────────────┘└─
1177        have h' : closed_ball x (n : ℝ) = closure (T (n : ℝ)) := by finish,
id                   └─────────┘            └─────┘    
src  ───────────────┘└─────────┘   └─┘ └┘ └─────┘    └─┘ └────┘  └────┘└─
typ  ───────────────┘└─────────┘  └─┘ └┘ └─────┘  └─┘ └────┘  └────┘└─
doc  ───────────────┘└─────────┘   └─┘ └┘ └─────┘    └─┘ └────┘  └────┘└─
txt  ───────────────┘              └─┘ └┘            └─┘ └────┘  └────┘└─
par  ───────────────┘              └─┘ └┘            └─┘ └────┘  └────┘└─
pid  ───────────────┘              └─┘ └┘            └─┘ └────┘  └────────
st   ────────────────────────────────────────────────────────────────┘└─────┘└─
1178        have : y ∈ closure (T (n : ℝ)) := by rwa h' at h,
id                   └─────┘                     └┘
src  ────────────┘  └─────┘    └─┘ └────┘  └──┘  └───┘└─
typ  ────────────┘ └─────┘  └─┘ └────┘  └──┘└┘└───┘└─
doc  ────────────┘  └─────┘    └─┘ └────┘  └──┘  └───┘└─
txt  ────────────┘             └─┘ └────┘  └──┘  └───┘└─
par  ────────────┘             └─┘ └────┘  └──┘  └───┘└─
pid  ────────────┘             └─┘ └────┘  └───┘  └──────
st   ─────────────────────────────────────────┘└──────────┘└─
1179        show y ∈ closure t, from mem_of_mem_of_subset this (by apply closure_mono; apply subset_Union (λ(n:ℕ), T (n:ℝ))),
id                 └─────┘        └──────────────────┘ └──┘           └──────────┘        └──────────┘          
src  ─────┘└───┘  └─────┘ └┘└───┘└──────────────────┘       └────┘└──────────┘└┘└────┘└──────────┘  └─┘ └─┘    └┘└─
typ  ─────┘└───┘ └─────┘└┘└───┘└──────────────────┘└──┘   └─────┘└──────────┘└──────┘└──────────┘  └─┘ └─┘   └─┘└─
doc  ─────┘└───┘  └─────┘ └┘└───┘                           └────┘            └┘└────┘              └─┘ └─┘    └┘└─
txt  ─────┘└───┘          └┘└───┘                           └────┘            └┘└────┘              └─┘ └─┘    └┘└─
par  ─────┘└───┘          └┘└───┘                           └─────┘            └──────┘              └─┘ └─┘    └─┘└─
pid  ──────────┘          └─────┘                           └─────┘            └──────┘              └─┘ └─┘    └────
st   ───────────────────────────────────────────────────────────┘└───────────────────────────────────────────────────────┘└─
1180      end,
src  ─────────
typ  ─────────
doc  ─────────
txt  ─────────
par  ─────────
pid  ─────────
st   ──────┘└─
1181      exact ⟨t, ⟨T₁, subset.antisymm T₂ T₃⟩⟩
id                 └┘  └─────────────┘ └┘ └┘
src  ───┘└────┘  └┘   └┘└─────────────┘    └──
typ  ───┘└────┘ └┘ └┘└┘└─────────────┘└┘└┘└──
doc  ───┘└────┘  └┘   └┘                   └──
txt  ───┘└────┘  └┘   └┘                   └──
par  ───┘└────┘  └┘   └┘                   └──
pid  ─────────┘  └┘   └┘                   └──
st   ───────────────────────────────────────────
1182    end,
src  ─┘└─┘
typ  ─┘└─┘
doc  ─┘└─┘
txt  ─┘└─┘
par  ─┘└─┘
pid  ────┘
st   ─┘└─┘└─
1183    haveI : separable_space α := ⟨(eq_empty_or_nonempty univ).elim A B⟩,
id             └─────────────┘       └──────────────────┘ └──┘        
src    └──────┘└─────────────┘ └──┘  └──────────────────┘└──┘└─────┘  
typ    └──────┘└─────────────┘└──┘  └──────────────────┘└──┘└─────┘
doc    └──────┘└─────────────┘ └──┘                          └─────┘  
txt    └──────┘                └──┘                          └─────┘  
par    └──────┘                └──┘                          └─────┘  
pid         └┘                └──┘                          └─────┘  
st   ────────────────────────────────────────────────────────────────────┘└─
1184    apply emetric.second_countable_of_separable,
id           └───────────────────────────────────┘
src    └────┘└───────────────────────────────────┘
typ    └────┘└───────────────────────────────────┘
doc    └────┘└───────────────────────────────────┘
txt    └────┘
par    └────┘
pid         
st   ────────────────────────────────────────────┘└─
1185  end
st   ──┘
1186  
1187  /-- A finite product of proper spaces is proper. -/
1188  instance pi_proper_space {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
id                                            └─────┘       └──────────┘   
src                                            └─────┘         └──────────┘
typ                                           └─────┘       └──────────┘   
doc                                            └─────┘         └──────────┘
1189    [h : ∀b, proper_space (π b)] : proper_space (Πb, π b) :=
id             └──────────┘        └──────────┘      
src             └──────────┘          └──────────┘
typ            └──────────┘        └──────────┘      
doc             └──────────┘          └──────────┘
1190  begin
st   └─────
1191    refine proper_space_of_compact_closed_ball_of_le 0 (λx r hr, _),
id            └───────────────────────────────────────┘
src    └─────┘└───────────────────────────────────────┘└─┘  └────────┘
typ    └─────┘└───────────────────────────────────────┘└─┘  └────────┘
doc    └─────┘└───────────────────────────────────────┘└─┘  └────────┘
txt    └─────┘                                         └─┘  └────────┘
par    └─────┘                                         └─┘  └────────┘
pid                                                   └─┘  └────────┘
st   ────────────────────────────────────────────────────────────────┘└─
1192    rw closed_ball_pi _ hr,
id        └────────────┘   └┘
src    └─┘└────────────┘└─┘
typ    └─┘└────────────┘└─┘└┘
doc    └─┘└────────────┘└─┘
txt    └─┘              └─┘
par    └─┘              └─┘
pid                    └─┘
st   ───────────────────────┘└─
1193    apply compact_pi_infinite (λb, _),
id           └─────────────────┘
src    └────┘└─────────────────┘  └───┘
typ    └────┘└─────────────────┘  └───┘
doc    └────┘└─────────────────┘  └───┘
txt    └────┘                     └───┘
par    └────┘                     └───┘
pid                              └───┘
st   ──────────────────────────────────┘└─
1194    apply (h b).compact_ball
id             
src    └────┘   └─────────────┘
typ    └────┘ └─────────────┘
doc    └────┘   └─────────────┘
txt    └────┘   └─────────────┘
par    └────┘   └─────────────┘
pid            └───────────┘└┘
st   ──────────────────────────┘
1195  end
st   └─┘
1196  
1197  end proper_space
1198  
1199  namespace metric
1200  section second_countable
1201  open topological_space
1202  
1203  /-- A metric space is second countable if, for every ε > 0, there is a countable set which is ε-dense. -/
1204  lemma second_countable_of_almost_dense_set
1205    (H : ∀ε > (0 : ℝ), ∃ s : set α, countable s ∧ (∀x, ∃y ∈ s, dist x y ≤ ε)) :
id                           └─┘  └───────┘           └──┘    
src                           └─┘   └───────┘               └──┘     
typ                          └─┘  └───────┘           └──┘    
doc                                    └───────┘
1206    second_countable_topology α :=
id     └───────────────────────┘ 
src    └───────────────────────┘
typ    └───────────────────────┘ 
doc    └───────────────────────┘
1207  begin
st   └─────
1208    choose T T_dense using H,
id                            
src    └─────────────────────┘
typ    └─────────────────────┘
doc    └─────────────────────┘
txt    └─────────────────────┘
par    └─────────────────────┘
pid          └┘└──────┘└─────┘
st   ─────────────────────────┘└─
1209    have I1 : ∀n:ℕ, (n:ℝ) + 1 > 0 :=
id                              
src    └────────┘ └┘     └┘└─┘└─────
typ    └────────┘ └┘     └┘└─┘└─────
doc    └────────┘ └┘     └┘ └─┘ └─────
txt    └────────┘ └┘     └┘ └─┘ └─────
par    └────────┘ └┘     └┘ └─┘ └─────
pid    └─────┘└─┘ └┘     └┘ └─┘ └────
st   ───────────────────────────────────
1210      λn, lt_of_lt_of_le zero_lt_one (le_add_of_nonneg_left (nat.cast_nonneg _)),
id           └────────────┘ └─────────┘  └───────────────────┘  └─────────────┘
src  ───┘ └─┘└────────────┘└─────────┘ └───────────────────┘ └─────────────┘└──┘
typ  ───┘ └─┘└────────────┘└─────────┘ └───────────────────┘ └─────────────┘└──┘
doc  ───┘ └─┘                                                               └──┘
txt  ───┘ └─┘                                                               └──┘
par  ───┘ └─┘                                                               └──┘
pid  ───┘ └─┘                                                               └──┘
st   ─────────────────────────────────────────────────────────────────────────────┘└─
1211    have I : ∀n:ℕ, (n+1 : ℝ)⁻¹ > 0 := λn, inv_pos'.2 (I1 n),
id                             └┘            └──────┘    └┘
src    └───────┘ └┘     └──┘ └┘ └────┘ └─┘└──────┘└─┘    
typ    └───────┘ └┘     └──┘ └┘ └────┘ └─┘└──────┘└─┘ └┘ 
doc    └───────┘ └┘     └──┘    └────┘ └─┘        └─┘    
txt    └───────┘ └┘     └──┘    └────┘ └─┘        └─┘    
par    └───────┘ └┘     └──┘    └────┘ └─┘        └─┘    
pid    └────┘└─┘ └┘     └──┘    └───┘ └─┘        └─┘    
st   ────────────────────────────────────────────────────────┘└─
1212    let t := ⋃n:ℕ, T (n+1)⁻¹ (I n),
id                            
src    └───────┘└┘     └┘     
typ    └───────┘└┘    └┘    
doc    └───────┘└┘     └┘     
txt    └───────┘ └┘      └┘     
par    └───────┘ └┘      └┘     
pid    └───┘└─┘ └┘      └┘     
st   ───────────────────────────────┘└─
1213    have count_t : countable t := by finish [countable_Union],
id                    └───────┘                └─────────────┘
src    └─────────────┘└───────┘ └──┘  └──────┘└─────────────┘
typ    └─────────────┘└───────┘└──┘  └──────┘└─────────────┘
doc    └─────────────┘└───────┘ └──┘  └──────┘               
txt    └─────────────┘          └──┘  └──────┘               
par    └─────────────┘          └──┘  └──────┘               
pid    └──────────┘└─┘          └──┘  └───────┘               
st   ─────────────────────────────────┘└───────────────────────┘└─
1214    have clos_t : closure t = univ,
id                   └─────┘   └──┘
src    └────────────┘└─────┘ └──┘
typ    └────────────┘└─────┘└──┘
doc    └────────────┘└─────┘  
txt    └────────────┘         
par    └────────────┘         
pid    └─────────┘└─┘         
st   ───────────────────────────────┘└─
1215    { refine subset.antisymm (subset_univ _) (λx xuniv, mem_closure_iff'.2 (λε εpos, _)),
id              └─────────────┘  └─────────┘               └──────────────┘
src      └─────┘└─────────────┘ └─────────┘└──┘  └───────┘└──────────────┘└─┘  └─────────┘
typ      └─────┘└─────────────┘ └─────────┘└──┘  └───────┘└──────────────┘└─┘  └─────────┘
doc      └─────┘                           └──┘  └───────┘└──────────────┘└─┘  └─────────┘
txt      └─────┘                           └──┘  └───────┘                └─┘  └─────────┘
par      └─────┘                           └──┘  └───────┘                └─┘  └─────────┘
pid                                       └──┘  └───────┘                └─┘  └─────────┘
st   ───┘└────────────────────────────────────────────────────────────────────────────────┘└─
1216      rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩,
id              └───────────┘ 
src      └─────┘└───────────┘   └───────────┘
typ      └─────┘└───────────┘  └───────────┘
doc      └─────┘                └───────────┘
txt      └─────┘                └───────────┘
par      └─────┘                └───────────┘
pid                            └───────────┘
st   ────────────────────────────────────────┘└─
1217      have : ε⁻¹ < n + 1 := lt_of_lt_of_le hn (le_add_of_nonneg_right zero_le_one),
id                          └────────────┘ └┘  └────────────────────┘ └─────────┘
src      └─────┘     └────┘└────────────┘   └────────────────────┘└─────────┘
typ      └─────┘   └────┘└────────────┘└┘ └────────────────────┘└─────────┘
doc      └─────┘      └────┘                                                  
txt      └─────┘      └────┘                                                  
par      └─────┘      └────┘                                                  
pid      └───┘└┘      └───┘                                                  
st   ───────────────────────────────────────────────────────────────────────────────┘└─
1218      have nε : ((n:ℝ)+1)⁻¹ < ε := (inv_lt (I1 n) εpos).2 this,
id                                   └────┘  └┘   └──┘    └──┘
src      └────────┘     └┘    └──┘ └────┘    └┘    └──┘
typ      └────────┘    └┘   └──┘ └────┘ └┘└┘└──┘└──┘└──┘
doc      └────────┘     └┘    └──┘           └┘    └──┘
txt      └────────┘     └┘    └──┘           └┘    └──┘
par      └────────┘     └┘    └──┘           └┘    └──┘
pid      └─────┘└─┘     └┘    └──┘           └┘    └──┘
st   ───────────────────────────────────────────────────────────┘└─
1219      rcases (T_dense (n+1)⁻¹ (I n)).2 x with ⟨y, yT, Dxy⟩,
id               └─────┘                
src      └─────┘           └┘     └───┘ └────────────────┘
typ      └─────┘ └─────┘   └┘   └───┘└────────────────┘
doc      └─────┘           └┘     └───┘ └────────────────┘
txt      └─────┘           └┘     └───┘ └────────────────┘
par      └─────┘           └┘     └───┘ └────────────────┘
pid                       └┘     └───┘ └────────────────┘
st   ───────────────────────────────────────────────────────┘└─
1220      have : y ∈ t := mem_of_mem_of_subset yT (by apply subset_Union (λ (n:ℕ), T (n+1)⁻¹ (I n))),
id                    └──────────────────┘ └┘           └──────────┘                     
src      └─────┘  └──┘└──────────────────┘     └────┘└──────────┘  └──┘ └─┘    └┘     └┘
typ      └─────┘└──┘└──────────────────┘└┘   └────┘└──────────┘  └──┘ └─┘   └┘    └┘
doc      └─────┘   └──┘                         └────┘              └──┘ └─┘    └┘     └┘
txt      └─────┘   └──┘                         └────┘              └──┘ └─┘    └┘     └┘
par      └─────┘   └──┘                         └────┘              └──┘ └─┘    └┘     └┘
pid      └───┘└┘   └──┘                         └─────┘              └──┘ └─┘    └┘     └─┘
st   ──────────────────────────────────────────────┘└────────────────────────────────────────────┘└─
1221      exact ⟨y, this, lt_of_le_of_lt Dxy nε⟩ },
id                └──┘  └────────────┘ └─┘ └┘
src      └────┘  └┘    └┘└────────────┘     └┘
typ      └────┘ └┘└──┘└┘└────────────┘└─┘└┘└┘
doc      └────┘  └┘    └┘                   └┘
txt      └────┘  └┘    └┘                   └┘
par      └────┘  └┘    └┘                   └┘
pid             └┘    └┘                   
st   ──────────────────────────────────────────┘└┘
1222    haveI : separable_space α := ⟨⟨t, ⟨count_t, clos_t⟩⟩⟩,
id             └─────────────┘          └─────┘  └────┘
src    └──────┘└─────────────┘ └──┘   └┘        └┘      └─┘
typ    └──────┘└─────────────┘└──┘  └┘ └─────┘└┘└────┘└─┘
doc    └──────┘└─────────────┘ └──┘   └┘        └┘      └─┘
txt    └──────┘                └──┘   └┘        └┘      └─┘
par    └──────┘                └──┘   └┘        └┘      └─┘
pid         └┘                └──┘   └┘        └┘      └─┘
st   ──────────────────────────────────────────────────────┘└─
1223    exact emetric.second_countable_of_separable α
id           └───────────────────────────────────┘ 
src    └────┘└───────────────────────────────────┘ 
typ    └────┘└───────────────────────────────────┘
doc    └────┘└───────────────────────────────────┘ 
txt    └────┘                                      
par    └────┘                                      
pid                                               
st   ───────────────────────────────────────────────┘
1224  end
st   └─┘
1225  
1226  /-- A metric space space is second countable if one can reconstruct up to any ε>0 any element of the
1227  space from countably many data. -/
1228  lemma second_countable_of_countable_discretization {α : Type u} [metric_space α]
id                                                                    └──────────┘ 
src                                                                   └──────────┘
typ                                                                   └──────────┘ 
doc                                                                   └──────────┘
1229    (H : ∀ε > (0 : ℝ), ∃ (β : Type u) [encodable β] (F : α → β), ∀x y, F x = F y → dist x y ≤ ε) :
id                            └──┘     └───────┘                       └──┘    
src                                     └───────┘                                 └──┘     
typ                           └──┘     └───────┘                       └──┘    
doc                                       └───────┘
1230    second_countable_topology α :=
id     └───────────────────────┘ 
src    └───────────────────────┘
typ    └───────────────────────┘ 
doc    └───────────────────────┘
1231  begin
st   └─────
1232    cases (univ : set α).eq_empty_or_nonempty with hs hs,
id            └──┘   └─┘ 
src    └────┘ └──┘└─┘└─┘ └───────────────────────────────┘
typ    └────┘ └──┘└─┘└─┘└───────────────────────────────┘
doc    └────┘     └─┘    └───────────────────────────────┘
txt    └────┘     └─┘    └───────────────────────────────┘
par    └────┘     └─┘    └───────────────────────────────┘
pid              └─┘    └───────────────────┘└──────────┘
st   ─────────────────────────────────────────────────────┘└─
1233    { haveI : compact_space α := ⟨by rw hs; exact compact_empty⟩, by apply_instance },
id               └───────────┘            └┘        └───────────┘
src      └──────┘└───────────┘ └──┘   └─┘  └┘└────┘└───────────┘     └─────────────┘
typ      └──────┘└───────────┘└──┘   └─┘└┘└┘└────┘└───────────┘     └─────────────┘
doc      └──────┘└───────────┘ └──┘   └─┘  └┘└────┘                  └─────────────┘
txt      └──────┘              └──┘   └─┘  └┘└────┘                  └─────────────┘
par      └──────┘              └──┘   └─┘  └┘└────┘                  └─────────────┘
pid           └┘              └──┘   └──┘  └──────┘                                
st   ───┘└────────────────────────────┘└─────────────────────────┘                    └┘
1234    rcases hs with ⟨x0, hx0⟩,
id            └┘
src    └─────┘  └─────────────┘
typ    └─────┘└┘└─────────────┘
doc    └─────┘  └─────────────┘
txt    └─────┘  └─────────────┘
par    └─────┘  └─────────────┘
pid            └─────────────┘
st   ─────────────────────────┘└─
1235    letI : inhabited α := ⟨x0⟩,
id            └───────┘      └┘
src    └─────┘└───────┘ └──┘   
typ    └─────┘└───────┘└──┘ └┘
doc    └─────┘          └──┘   
txt    └─────┘          └──┘   
par    └─────┘          └──┘   
pid        └┘          └──┘   
st   ───────────────────────────┘└─
1236    refine second_countable_of_almost_dense_set (λε ε0, _),
id            └──────────────────────────────────┘
src    └─────┘└──────────────────────────────────┘  └──────┘
typ    └─────┘└──────────────────────────────────┘  └──────┘
doc    └─────┘└──────────────────────────────────┘  └──────┘
txt    └─────┘                                      └──────┘
par    └─────┘                                      └──────┘
pid                                                └──────┘
st   ───────────────────────────────────────────────────────┘└─
1237    rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
id              └┘
src    └─────┘    └──────────────────┘
typ    └─────┘└┘└──────────────────┘
doc    └─────┘    └──────────────────┘
txt    └─────┘    └──────────────────┘
par    └─────┘    └──────────────────┘
pid              └──────────────────┘
st   ──────────────────────────────────┘└─
1238    let Finv := function.inv_fun F,
id                 └──────────────┘ 
src    └──────────┘└──────────────┘
typ    └──────────┘└──────────────┘
doc    └──────────┘└──────────────┘
txt    └──────────┘                
par    └──────────┘                
pid    └──────┘└─┘                
st   ───────────────────────────────┘└─
1239    refine ⟨range Finv, ⟨countable_range _, λx, _⟩⟩,
id             └───┘ └──┘   └─────────────┘
src    └─────┘ └───┘    └┘ └─────────────┘└──┘ └────┘
typ    └─────┘ └───┘└──┘└┘ └─────────────┘└──┘ └────┘
doc    └─────┘ └───┘    └┘                └──┘ └────┘
txt    └─────┘          └┘                └──┘ └────┘
par    └─────┘          └┘                └──┘ └────┘
pid                    └┘                └──┘ └────┘
st   ────────────────────────────────────────────────┘└─
1240    let x' := Finv (F x),
id               └──┘   
src    └────────┘       
typ    └────────┘└──┘ 
doc    └────────┘       
txt    └────────┘       
par    └────────┘       
pid    └────┘└─┘       
st   ─────────────────────┘└─
1241    have : F x' = F x := function.inv_fun_eq ⟨x, rfl⟩,
id              └┘       └─────────────────┘    └─┘
src    └─────┘     └──┘└─────────────────┘  └┘└─┘
typ    └─────┘ └┘└──┘└─────────────────┘ └┘└─┘
doc    └─────┘      └──┘                     └┘   
txt    └─────┘      └──┘                     └┘   
par    └─────┘      └──┘                     └┘   
pid    └───┘└┘      └──┘                     └┘   
st   ──────────────────────────────────────────────────┘└─
1242    exact ⟨x', mem_range_self _, hF _ _ this.symm⟩
id            └┘  └────────────┘    └┘     └───────┘
src    └────┘   └┘└────────────┘└──┘  └───┘└───────┘└┘
typ    └────┘ └┘└┘└────────────┘└──┘└┘└───┘└───────┘└┘
doc    └────┘   └┘              └──┘  └───┘         └┘
txt    └────┘   └┘              └──┘  └───┘         └┘
par    └────┘   └┘              └──┘  └───┘         └┘
pid            └┘              └──┘  └───┘         
st   ────────────────────────────────────────────────┘
1243  end
st   └─┘
1244  
1245  end second_countable
1246  end metric
1247  
1248  lemma lebesgue_number_lemma_of_metric
1249    {s : set α} {ι} {c : ι → set α} (hs : compact s)
id          └─┘               └─┘         └─────┘ 
src         └─┘                 └─┘          └─────┘
typ         └─┘               └─┘         └─────┘ 
doc                                          └─────┘
1250    (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
id                └─────┘                  
src                └─────┘                    
typ               └─────┘                  
doc                └─────┘                     
1251    ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=
id                    └──┘     
src                       └──┘     
typ                   └──┘     
doc                           └──┘
1252  let ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂,
id   └─┘     └┘  └┘     └───────────────────┘ └┘ └─┘ └─┘
src                     └───────────────────┘
typ  └─┘     └┘  └┘     └───────────────────┘ └┘ └─┘ └─┘
1253      ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en in
id          └┘  └┘     └─────────────────┘
src                     └─────────────────┘
typ         └┘  └┘     └─────────────────┘
1254  ⟨δ, δ0, assume x hx, let ⟨i, hi⟩ := hn x hx in
id                   └┘  └─┘    └┘         └┘
typ                  └┘  └─┘    └┘         └┘
1255   ⟨i, assume y hy, hi (hδ (mem_ball'.mp hy))⟩⟩
id                └┘          └───────┘└─┘ └┘
src                            └───────┘└─┘
typ               └┘          └───────┘└─┘ └┘
1256  
1257  lemma lebesgue_number_lemma_of_metric_sUnion
1258    {s : set α} {c : set (set α)} (hs : compact s)
id          └─┘        └─┘  └─┘          └─────┘ 
src         └─┘         └─┘  └─┘           └─────┘
typ         └─┘        └─┘  └─┘          └─────┘ 
doc                                        └─────┘
1259    (hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
id                   └─────┘            └┘ 
src                    └─────┘              └┘
typ                  └─────┘            └┘ 
doc                    └─────┘
1260    ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t :=
id                       └──┘    
src                           └──┘     
typ                      └──┘    
doc                               └──┘
1261  by rw sUnion_eq_Union at hc₂;
id         └─────────────┘
src     └─┘└─────────────┘└─────┘
typ     └─┘└─────────────┘└─────┘
doc     └─┘               └─────┘
txt     └─┘               └─────┘
par     └─┘               └─────┘
pid                      └─────┘
st     └───────────────────────────
1262     simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
id                  └─────────────────────────────┘ └┘            └─┘
src     └──────────┘└─────────────────────────────┘     └──────┘   
typ     └──────────┘└─────────────────────────────┘└┘   └──────┘└─┘
doc     └──────────┘                                    └──────┘   
txt     └──────────┘                                    └──────┘   
par     └──────────┘                                    └──────┘   
pid          └────┘                                    └──────┘   
st   ────────────────────────────────────────────────────┘└────┘└─────
1263  
src  
typ  
doc  
txt  
par  
pid  
st   
1264  namespace metric
1265  
1266  /-- Boundedness of a subset of a metric space. We formulate the definition to work
1267  even in the empty space. -/
1268  def bounded (s : set α) : Prop :=
id                    └─┘ 
src                   └─┘
typ                   └─┘ 
1269  ∃C, ∀x y ∈ s, dist x y ≤ C
id           └──┘    
src              └──┘     
typ          └──┘    
1270  
1271  section bounded
1272  variables {x : α} {s t : set α} {r : ℝ}
id                            └─┘         
src                           └─┘         
typ                           └─┘         
1273  
1274  @[simp] lemma bounded_empty : bounded (∅ : set α) :=
id                                 └─────┘     └─┘ 
src                                └─────┘     └─┘
typ                                └─────┘     └─┘ 
doc    └──┘                        └─────┘
1275  ⟨0, by simp⟩
src         └──┘
typ         └──┘
doc         └──┘
txt         └──┘
par         └──┘
st         └───┘
1276  
1277  lemma bounded_iff_mem_bounded : bounded s ↔ ∀ x ∈ s, bounded s :=
id                                   └─────┘          └─────┘ 
src                                  └─────┘             └─────┘
typ                                  └─────┘          └─────┘ 
doc                                  └─────┘              └─────┘
1278  ⟨λ h _ _, h, λ H, 
id              
typ             
1279    s.eq_empty_or_nonempty.elim
id     └───────────────────┘└───┘
src     └───────────────────┘└───┘
typ    └───────────────────┘└───┘
1280    (λ hs, hs.symm ▸ bounded_empty)
id        └┘  └┘└───┘  └───────────┘
src             └───┘  └───────────┘
typ       └┘  └┘└───┘  └───────────┘
1281    (λ ⟨x, hx⟩, H x hx)⟩
id          └┘   
typ         └┘   
1282  
1283  /-- Subsets of a bounded set are also bounded -/
1284  lemma bounded.subset (incl : s ⊆ t) : bounded t → bounded s :=
id                                      └─────┘    └─────┘ 
src                                       └─────┘     └─────┘
typ                                     └─────┘    └─────┘ 
doc                                        └─────┘     └─────┘
1285  Exists.imp $ λ C hC x y hx hy, hC x y (incl hx) (incl hy)
id   └────────┘      └┘   └┘ └┘  └┘    └──┘ └┘   └──┘ └┘
src  └────────┘
typ  └────────┘      └┘   └┘ └┘  └┘    └──┘ └┘   └──┘ └┘
1286  
1287  /-- Closed balls are bounded -/
1288  lemma bounded_closed_ball : bounded (closed_ball x r) :=
id                               └─────┘  └─────────┘  
src                              └─────┘  └─────────┘
typ                              └─────┘  └─────────┘  
doc                              └─────┘  └─────────┘
1289  ⟨r + r, λ y z hy hz, begin
id            └┘ └┘
src     
typ           └┘ └┘
st                        └─────
1290    simp only [mem_closed_ball] at *,
id                └─────────────┘
src    └─────────┘└─────────────┘└────┘
typ    └─────────┘└─────────────┘└────┘
doc    └─────────┘               └────┘
txt    └─────────┘               └────┘
par    └─────────┘               └────┘
pid        └──┘└┘               └──┘
st   ─────────────────────────────────┘└─
1291    calc dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _
id     └──┘                     └──┘     └─────────────────┘
src    └──┘                      └──┘       └─────────────────┘
typ    └──┘                     └──┘     └─────────────────┘
doc    └──┘
st   ──────────────────────────────────────────────────────────────────
1292              ... ≤ r + r : add_le_add hy hz
id                            └────────┘ └┘ └┘
src                            └────────┘
typ                           └────────┘ └┘ └┘
st   ─────────────────────────────────────────┘
1293  end⟩
st   ──┘
1294  
1295  /-- Open balls are bounded -/
1296  lemma bounded_ball : bounded (ball x r) :=
id                        └─────┘  └──┘  
src                       └─────┘  └──┘
typ                       └─────┘  └──┘  
doc                       └─────┘  └──┘
1297  bounded_closed_ball.subset ball_subset_closed_ball
id   └─────────────────┘└─────┘ └─────────────────────┘
src  └─────────────────┘└─────┘ └─────────────────────┘
typ  └─────────────────┘└─────┘ └─────────────────────┘
doc  └─────────────────┘└─────┘
1298  
1299  /-- Given a point, a bounded subset is included in some ball around this point -/
1300  lemma bounded_iff_subset_ball (c : α) : bounded s ↔ ∃r, s ⊆ closed_ball c r :=
id                                          └─────┘      └─────────┘  
src                                          └─────┘         └─────────┘
typ                                         └─────┘      └─────────┘  
doc                                          └─────┘             └─────────┘
1301  begin
st   └─────
1302    split; rintro ⟨C, hC⟩,
src    └───┘  └────────────┘
typ    └───┘  └────────────┘
doc    └───┘  └────────────┘
txt    └───┘  └────────────┘
par    └───┘  └────────────┘
pid                 └──────┘
st   ──────────────────────┘└─
1303    { cases s.eq_empty_or_nonempty with h h,
id             └────────────────────┘
src      └────┘└────────────────────┘└───────┘
typ      └────┘└────────────────────┘└───────┘
doc      └────┘                      └───────┘
txt      └────┘                      └───────┘
par      └────┘                      └───────┘
pid                                 └───────┘
st   ───┘└───────────────────────────────────┘└─
1304      { subst s, exact ⟨0, by simp⟩ },
id               
src        └────┘   └────┘ └─┘  └──┘└┘
typ        └────┘  └────┘ └─┘  └──┘└┘
doc        └────┘   └────┘ └─┘  └──┘└┘
txt        └────┘   └────┘ └─┘  └──┘└┘
par        └────┘   └────┘ └─┘  └──┘└┘
pid                      └─┘  └────┘
st   ─────┘└─────┘└────────────┘└───┘└┘└┘
1305      { rcases h with ⟨x, hx⟩,
id                
src        └─────┘ └───────────┘
typ        └─────┘└───────────┘
doc        └─────┘ └───────────┘
txt        └─────┘ └───────────┘
par        └─────┘ └───────────┘
pid               └───────────┘
st   ──────────────────────────┘└─
1306        exact ⟨C + dist x c, λ y hy, calc
id                  
src        └────┘        └┘ └─────┘    
typ        └────┘        └┘ └─────┘    
doc        └────┘         └┘ └─────┘    
txt        └────┘         └┘ └─────┘    
par        └────┘         └┘ └─────┘    
pid                      └┘ └─────┘    
st   ────────────────────────────────────────
1307          dist y c ≤ dist y x + dist x c : dist_triangle _ _ _
id                                            └───────────┘
src  ───────┘                    └─┘└───────────┘└──────
typ  ───────┘                    └─┘└───────────┘└──────
doc  ───────┘                    └─┘             └──────
txt  ───────┘                    └─┘             └──────
par  ───────┘                    └─┘             └──────
pid  ───────┘                    └─┘             └──────
st   ─────────────────────────────────────────────────────────────
1308              ... ≤ C + dist x c : add_le_add_right (hC y x hy hx) _⟩ } },
id                        └──┘      └──────────────┘  └┘       └┘
src  ───────────────┘   └──┘  └─┘└──────────────┘         └───┘
typ  ───────────────┘  └──┘ └─┘└──────────────┘ └┘   └┘└───┘
doc  ───────────────┘         └─┘                         └───┘
txt  ───────────────┘         └─┘                         └───┘
par  ───────────────┘         └─┘                         └───┘
pid  ───────────────┘         └─┘                         └──┘
st   ───────────────────────────────────────────────────────────────────┘└──┘
1309    { exact bounded_closed_ball.subset hC }
id             └────────────────────────┘ └┘
src      └────┘└────────────────────────┘  
typ      └────┘└────────────────────────┘└┘
doc      └────┘└────────────────────────┘  
txt      └────┘                            
par      └────┘                            
pid                                       
st   ───────────────────────────────────────┘└─
1310  end
st   ──┘
1311  
1312  /-- The union of two bounded sets is bounded iff each of the sets is bounded -/
1313  @[simp] lemma bounded_union :
doc    └──┘
1314    bounded (s ∪ t) ↔ bounded s ∧ bounded t :=
id     └─────┘       └─────┘   └─────┘ 
src    └─────┘         └─────┘    └─────┘
typ    └─────┘       └─────┘   └─────┘ 
doc    └─────┘           └─────┘     └─────┘
1315  ⟨λh, ⟨h.subset (by simp), h.subset (by simp)⟩,
id        └─────┘            └─────┘
src         └─────┘     └──┘    └─────┘     └──┘
typ       └─────┘     └──┘   └─────┘     └──┘
doc         └─────┘     └──┘    └─────┘     └──┘
txt                     └──┘                └──┘
par                     └──┘                └──┘
st                     └───┘               └───┘
1316  begin
st   └─────
1317    rintro ⟨hs, ht⟩,
src    └─────────────┘
typ    └─────────────┘
doc    └─────────────┘
txt    └─────────────┘
par    └─────────────┘
pid          └───────┘
st   ────────────────┘└─
1318    refine bounded_iff_mem_bounded.2 (λ x _, _),
id            └─────────────────────┘
src    └─────┘└─────────────────────┘└─┘  └──────┘
typ    └─────┘└─────────────────────┘└─┘  └──────┘
doc    └─────┘                       └─┘  └──────┘
txt    └─────┘                       └─┘  └──────┘
par    └─────┘                       └─┘  └──────┘
pid                                 └─┘  └──────┘
st   ────────────────────────────────────────────┘└─
1319    rw bounded_iff_subset_ball x at hs ht ⊢,
id        └─────────────────────┘ 
src    └─┘└─────────────────────┘ └─────────┘
typ    └─┘└─────────────────────┘└─────────┘
doc    └─┘└─────────────────────┘ └─────────┘
txt    └─┘                        └─────────┘
par    └─┘                        └─────────┘
pid                              └─────────┘
st   ────────────────────────────────────────┘└─
1320    rcases hs with ⟨Cs, hCs⟩, rcases ht with ⟨Ct, hCt⟩,
id            └┘                        └┘
src    └─────┘  └─────────────┘  └─────┘  └─────────────┘
typ    └─────┘└┘└─────────────┘  └─────┘└┘└─────────────┘
doc    └─────┘  └─────────────┘  └─────┘  └─────────────┘
txt    └─────┘  └─────────────┘  └─────┘  └─────────────┘
par    └─────┘  └─────────────┘  └─────┘  └─────────────┘
pid            └─────────────┘          └─────────────┘
st   ─────────────────────────┘└────────────────────────┘└─
1321    exact ⟨max Cs Ct, union_subset
id            └─┘ └┘ └┘  └──────────┘
src    └────┘ └─┘    └┘└──────────┘
typ    └────┘ └─┘└┘└┘└┘└──────────┘
doc    └────┘        └┘            
txt    └────┘        └┘            
par    └────┘        └┘            
pid                 └┘            
st   ─────────────────────────────────
1322      (subset.trans hCs $ closed_ball_subset_closed_ball $ le_max_left _ _)
id                     └─┘                                    └─────────┘
src  ───┘                                                └─────────┘└─────
typ  ───┘             └─┘                                └─────────┘└─────
doc  ───┘                                                           └─────
txt  ───┘                                                           └─────
par  ───┘                                                           └─────
pid  ───┘                                                           └─────
st   ──────────────────────────────────────────────────────────────────────────
1323      (subset.trans hCt $ closed_ball_subset_closed_ball $ le_max_right _ _)⟩,
id        └──────────┘ └─┘   └────────────────────────────┘   └──────────┘
src  ───┘ └──────────┘    └────────────────────────────┘ └──────────┘└────┘
typ  ───┘ └──────────┘└─┘ └────────────────────────────┘ └──────────┘└────┘
doc  ───┘                                                            └────┘
txt  ───┘                                                            └────┘
par  ───┘                                                            └────┘
pid  ───┘                                                            └────┘
st   ──────────────────────────────────────────────────────────────────────────┘└─
1324  end⟩
st   ──┘
1325  
1326  /-- A finite union of bounded sets is bounded -/
1327  lemma bounded_bUnion {I : set β} {s : β → set α} (H : finite I) :
id                             └─┘           └─┘        └────┘ 
src                            └─┘             └─┘         └────┘
typ                            └─┘           └─┘        └────┘ 
doc                                                        └────┘
1328    bounded (⋃i∈I, s i) ↔ ∀i ∈ I, bounded (s i) :=
id     └─────┘              └─────┘   
src    └─────┘                    └─────┘
typ    └─────┘              └─────┘   
doc    └─────┘                     └─────┘
1329  finite.induction_on H (by simp) $ λ x I _ _ IH,
id   └─────────────────┘                    └┘
src  └─────────────────┘       └──┘
typ  └─────────────────┘      └──┘          └┘
doc                            └──┘
txt                            └──┘
par                            └──┘
st                            └───┘
1330  by simp [or_imp_distrib, forall_and_distrib, IH]
id            └────────────┘  └────────────────┘  └┘
src     └────┘└────────────┘└┘└────────────────┘└┘  └─
typ     └────┘└────────────┘└┘└────────────────┘└┘└┘└─
doc     └────┘              └┘                  └┘  └─
txt     └────┘              └┘                  └┘  └─
par     └────┘              └┘                  └┘  └─
pid                       └┘                  └┘  
st     └──────────────────────────────────────────────
1331  
src  
typ  
doc  
txt  
par  
pid  
st   
1332  /-- A compact set is bounded -/
1333  lemma bounded_of_compact {s : set α} (h : compact s) : bounded s :=
id                                 └─┘        └─────┘     └─────┘ 
src                                └─┘         └─────┘      └─────┘
typ                                └─┘        └─────┘     └─────┘ 
doc                                            └─────┘      └─────┘
1334  -- We cover the compact set by finitely many balls of radius 1,
1335  -- and then argue that a finite union of bounded sets is bounded
1336  let ⟨t, ht, fint, subs⟩ := finite_cover_balls_of_compact h zero_lt_one in
id   └─┘         └──┘  └──┘     └───────────────────────────┘  └─────────┘
src                             └───────────────────────────┘   └─────────┘
typ  └─┘         └──┘  └──┘     └───────────────────────────┘  └─────────┘
doc                             └───────────────────────────┘
1337  bounded.subset subs $ (bounded_bUnion fint).2 $ λ i hi, bounded_ball
id   └────────────┘         └────────────┘             └┘  └──────────┘
src  └────────────┘         └────────────┘                  └──────────┘
typ  └────────────┘         └────────────┘             └┘  └──────────┘
doc  └────────────┘         └────────────┘                   └──────────┘
1338  
1339  alias bounded_of_compact ← compact.bounded
1340  
1341  /-- A finite set is bounded -/
1342  lemma bounded_of_finite {s : set α} (h : finite s) : bounded s :=
id                                └─┘        └────┘     └─────┘ 
src                               └─┘         └────┘      └─────┘
typ                               └─┘        └────┘     └─────┘ 
doc                                           └────┘      └─────┘
1343  h.compact.bounded
id   └──────┘└──────┘
src   └──────┘
typ  └──────┘└──────┘
doc           └──────┘
1344  
1345  /-- A singleton is bounded -/
1346  lemma bounded_singleton {x : α} : bounded ({x} : set α) :=
id                                    └─────┘      └─┘ 
src                                    └─────┘       └─┘
typ                                   └─────┘      └─┘ 
doc                                    └─────┘
1347  bounded_of_finite $ finite_singleton _
id   └───────────────┘   └──────────────┘
src  └───────────────┘   └──────────────┘
typ  └───────────────┘   └──────────────┘
doc  └───────────────┘
1348  
1349  /-- Characterization of the boundedness of the range of a function -/
1350  lemma bounded_range_iff {f : β → α} : bounded (range f) ↔ ∃C, ∀x y, dist (f x) (f y) ≤ C :=
id                                       └─────┘  └───┘         └──┘          
src                                        └─────┘  └───┘             └──┘             
typ                                      └─────┘  └───┘         └──┘          
doc                                        └─────┘  └───┘
1351  exists_congr $ λ C, ⟨
id   └──────────┘     
src  └──────────┘
typ  └──────────┘     
1352    λ H x y, H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩,
id                   └─┘     └─┘
src                       └─┘      └─┘
typ                  └─┘     └─┘
1353    by rintro H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact H x y⟩
id                                                
src       └────────────────────────────┘  └────┘  
typ       └────────────────────────────┘  └────┘
doc       └────────────────────────────┘  └────┘  
txt       └────────────────────────────┘  └────┘  
par       └────────────────────────────┘  └────┘  
pid             └──────────────────────┘         
st       └──────────────────────────────────────────┘
1354  
1355  /-- In a compact space, all sets are bounded -/
1356  lemma bounded_of_compact_space [compact_space α] : bounded s :=
id                                   └───────────┘     └─────┘ 
src                                  └───────────┘      └─────┘
typ                                  └───────────┘     └─────┘ 
doc                                  └───────────┘      └─────┘
1357  compact_univ.bounded.subset (subset_univ _)
id   └──────────┘└──────┘└─────┘  └─────────┘
src  └──────────┘        └─────┘  └─────────┘
typ  └──────────┘└──────┘└─────┘  └─────────┘
doc              └──────┘└─────┘
1358  
1359  /-- In a proper space, a set is compact if and only if it is closed and bounded -/
1360  lemma compact_iff_closed_bounded [proper_space α] :
id                                     └──────────┘ 
src                                    └──────────┘
typ                                    └──────────┘ 
doc                                    └──────────┘
1361    compact s ↔ is_closed s ∧ bounded s :=
id     └─────┘   └───────┘   └─────┘ 
src    └─────┘    └───────┘    └─────┘
typ    └─────┘   └───────┘   └─────┘ 
doc    └─────┘     └───────┘     └─────┘
1362  ⟨λ h, ⟨closed_of_compact _ h, h.bounded⟩, begin
id         └───────────────┘     └──────┘
src         └───────────────┘
typ        └───────────────┘     └──────┘
doc                                 └──────┘
st                                             └─────
1363    rintro ⟨hc, hb⟩,
src    └─────────────┘
typ    └─────────────┘
doc    └─────────────┘
txt    └─────────────┘
par    └─────────────┘
pid          └───────┘
st   ────────────────┘└─
1364    cases s.eq_empty_or_nonempty with h h, {simp [h, compact_empty]},
id           └────────────────────┘                    └───────────┘
src    └────┘└────────────────────┘└───────┘   └────┘ └┘└───────────┘
typ    └────┘└────────────────────┘└───────┘   └────┘└┘└───────────┘
doc    └────┘                      └───────┘   └────┘ └┘             
txt    └────┘                      └───────┘   └────┘ └┘             
par    └────┘                      └───────┘   └────┘ └┘             
pid                               └───────┘        └┘             
st   ──────────────────────────────────────┘└────────────────────────┘└┘
1365    rcases h with ⟨x, hx⟩,
id            
src    └─────┘ └───────────┘
typ    └─────┘└───────────┘
doc    └─────┘ └───────────┘
txt    └─────┘ └───────────┘
par    └─────┘ └───────────┘
pid           └───────────┘
st   ──────────────────────┘└─
1366    rcases (bounded_iff_subset_ball x).1 hb with ⟨r, hr⟩,
id             └─────────────────────┘     └┘
src    └─────┘ └─────────────────────┘ └──┘  └───────────┘
typ    └─────┘ └─────────────────────┘└──┘└┘└───────────┘
doc    └─────┘ └─────────────────────┘ └──┘  └───────────┘
txt    └─────┘                         └──┘  └───────────┘
par    └─────┘                         └──┘  └───────────┘
pid                                   └──┘  └───────────┘
st   ─────────────────────────────────────────────────────┘└─
1367    exact compact_of_is_closed_subset (proper_space.compact_ball x r) hc hr
id           └─────────────────────────┘  └───────────────────────┘    └┘ └┘
src    └────┘└─────────────────────────┘ └───────────────────────┘  └┘    
typ    └────┘└─────────────────────────┘ └───────────────────────┘└┘└┘└┘
doc    └────┘                                                       └┘    
txt    └────┘                                                       └┘    
par    └────┘                                                       └┘    
pid                                                                └┘    
st   ─────────────────────────────────────────────────────────────────────────┘
1368  end⟩
st   └─┘
1369  
1370  /-- The image of a proper space under an expanding onto map is proper. -/
1371  lemma proper_image_of_proper [proper_space α] [metric_space β] (f : α → β)
id                                 └──────────┘    └──────────┘           
src                                └──────────┘     └──────────┘
typ                                └──────────┘    └──────────┘           
doc                                └──────────┘     └──────────┘
1372    (f_cont : continuous f) (hf : range f = univ) (C : ℝ)
id               └────────┘         └───┘   └──┘       
src              └────────┘          └───┘    └──┘       
typ              └────────┘         └───┘   └──┘       
doc              └────────┘          └───┘
1373    (hC : ∀x y, dist x y ≤ C * dist (f x) (f y)) : proper_space β :=
id               └──┘      └──┘            └──────────┘ 
src                └──┘         └──┘                └──────────┘
typ              └──┘      └──┘            └──────────┘ 
doc                                                   └──────────┘
1374  begin
st   └─────
1375    apply proper_space_of_compact_closed_ball_of_le 0 (λx₀ r hr, _),
id           └───────────────────────────────────────┘
src    └────┘└───────────────────────────────────────┘└─┘  └─────────┘
typ    └────┘└───────────────────────────────────────┘└─┘  └─────────┘
doc    └────┘└───────────────────────────────────────┘└─┘  └─────────┘
txt    └────┘                                         └─┘  └─────────┘
par    └────┘                                         └─┘  └─────────┘
pid                                                  └─┘  └─────────┘
st   ────────────────────────────────────────────────────────────────┘└─
1376    let K := f ⁻¹' (closed_ball x₀ r),
id               └─┘  └─────────┘ └┘ 
src    └───────┘ └─┘ └─────────┘   
typ    └───────┘└─┘ └─────────┘└┘
doc    └───────┘ └─┘ └─────────┘   
txt    └───────┘                   
par    └───────┘                   
pid    └───┘└─┘                   
st   ──────────────────────────────────┘└─
1377    have A : is_closed K :=
id              └───────┘ 
src    └───────┘└───────┘ └───
typ    └───────┘└───────┘└───
doc    └───────┘└───────┘ └───
txt    └───────┘          └───
par    └───────┘          └───
pid    └────┘└─┘          └───
st   ──────────────────────────
1378      continuous_iff_is_closed.1 f_cont (closed_ball x₀ r) (is_closed_ball),
id       └──────────────────────┘   └────┘  └─────────┘ └┘    └────────────┘
src  ───┘└──────────────────────┘└─┘       └─────────┘   └┘ └────────────┘
typ  ───┘└──────────────────────┘└─┘└────┘ └─────────┘└┘└┘ └────────────┘
doc  ───┘                        └─┘       └─────────┘   └┘               
txt  ───┘                        └─┘                     └┘               
par  ───┘                        └─┘                     └┘               
pid  ───┘                        └─┘                     └┘               
st   ────────────────────────────────────────────────────────────────────────┘└─
1379    have B : bounded K := ⟨max C 0 * (r + r), λx y hx hy, calc
id              └─────┘                  
src    └───────┘└─────┘ └──┘     └─┘   └─┘ └─────────┘    
typ    └───────┘└─────┘└──┘     └─┘   └─┘ └─────────┘    
doc    └───────┘└─────┘ └──┘     └─┘     └─┘ └─────────┘    
txt    └───────┘        └──┘     └─┘     └─┘ └─────────┘    
par    └───────┘        └──┘     └─┘     └─┘ └─────────┘    
pid    └────┘└─┘        └──┘     └─┘     └─┘ └─────────┘    
st   ─────────────────────────────────────────────────────────────
1380      dist x y ≤ C * dist (f x) (f y) : hC x y
id                     └──┘               └┘
src  ───┘         └──┘   └┘   └──┘    
typ  ───┘        └──┘   └┘   └──┘└┘  
doc  ───┘                └┘   └──┘    
txt  ───┘                └┘   └──┘    
par  ───┘                └┘   └──┘    
pid  ───┘                └┘   └──┘    
st   ─────────────────────────────────────────────
1381      ... ≤ max C 0 * dist (f x) (f y) : mul_le_mul_of_nonneg_right (le_max_left _ _) (dist_nonneg)
id             └─┘                          └────────────────────────┘  └─────────┘       └─────────┘
src  ───────┘ └─┘ └─┘        └┘   └──┘└────────────────────────┘ └─────────┘└────┘ └─────────┘└─
typ  ───────┘ └─┘ └─┘        └┘   └──┘└────────────────────────┘ └─────────┘└────┘ └─────────┘└─
doc  ───────┘     └─┘        └┘   └──┘                                      └────┘            └─
txt  ───────┘     └─┘        └┘   └──┘                                      └────┘            └─
par  ───────┘     └─┘        └┘   └──┘                                      └────┘            └─
pid  ───────┘     └─┘        └┘   └──┘                                      └────┘            └─
st   ──────────────────────────────────────────────────────────────────────────────────────────────────
1382      ... ≤ max C 0 * (dist (f x) x₀ + dist (f y) x₀) :
src  ───────┘     └─┘         └┘          └┘  └───
typ  ───────┘     └─┘         └┘          └┘  └───
doc  ───────┘     └─┘         └┘          └┘  └───
txt  ───────┘     └─┘         └┘          └┘  └───
par  ───────┘     └─┘         └┘          └┘  └───
pid  ───────┘     └─┘         └┘          └┘  └───
st   ──────────────────────────────────────────────────────
1383        mul_le_mul_of_nonneg_left (dist_triangle_right (f x) (f y) x₀) (le_max_right _ _)
id         └───────────────────────┘  └─────────────────┘            └┘   └──────────┘
src  ─────┘└───────────────────────┘ └─────────────────┘   └┘   └┘  └┘ └──────────┘└─────
typ  ─────┘└───────────────────────┘ └─────────────────┘   └┘  └┘└┘└┘ └──────────┘└─────
doc  ─────┘                                                └┘   └┘  └┘             └─────
txt  ─────┘                                                └┘   └┘  └┘             └─────
par  ─────┘                                                └┘   └┘  └┘             └─────
pid  ─────┘                                                └┘   └┘  └┘             └─────
st   ────────────────────────────────────────────────────────────────────────────────────────
1384      ... ≤ max C 0 * (r + r) : begin
id                            
src  ───────┘     └─┘     └──┘     
typ  ───────┘     └─┘    └──┘     
doc  ───────┘     └─┘     └──┘     
txt  ───────┘     └─┘     └──┘     
par  ───────┘     └─┘     └──┘     
pid  ───────┘     └─┘     └──┘     
st   ─────────────────────────────┘└─────
1385        simp only [mem_closed_ball, mem_preimage] at hx hy,
id                    └─────────────┘  └──────────┘
src  ─────┘└─────────┘└─────────────┘└┘└──────────┘└────────┘└─
typ  ─────┘└─────────┘└─────────────┘└┘└──────────┘└────────┘└─
doc  ─────┘└─────────┘               └┘            └────────┘└─
txt  ─────┘└─────────┘               └┘            └────────┘└─
par  ─────┘└─────────┘               └┘            └────────┘└─
pid  ────────────────┘               └┘            └───────────
st   ───────────────────────────────────────────────────────┘└─
1386        exact mul_le_mul_of_nonneg_left (add_le_add hx hy) (le_max_right _ _)
id               └───────────────────────┘  └────────┘ └┘ └┘   └──────────┘
src  ─────┘└────┘└───────────────────────┘ └────────┘    └┘ └──────────┘└─────
typ  ─────┘└────┘└───────────────────────┘ └────────┘└┘└┘└┘ └──────────┘└─────
doc  ─────┘└────┘                                        └┘             └─────
txt  ─────┘└────┘                                        └┘             └─────
par  ─────┘└────┘                                        └┘             └─────
pid  ───────────┘                                        └┘             └─────
st   ────────────────────────────────────────────────────────────────────────────
1387      end⟩,
src  ───┘└──┘
typ  ───┘└──┘
doc  ───┘└──┘
txt  ───┘└──┘
par  ───┘└──┘
pid  ───────┘
st   ───┘└─┘└─
1388    have : compact K := compact_iff_closed_bounded.2 ⟨A, B⟩,
id            └─────┘     └────────────────────────┘      
src    └─────┘└─────┘ └──┘└────────────────────────┘└─┘  └┘ 
typ    └─────┘└─────┘└──┘└────────────────────────┘└─┘ └┘
doc    └─────┘└─────┘ └──┘└────────────────────────┘└─┘  └┘ 
txt    └─────┘        └──┘                          └─┘  └┘ 
par    └─────┘        └──┘                          └─┘  └┘ 
pid    └───┘└┘        └──┘                          └─┘  └┘ 
st   ────────────────────────────────────────────────────────┘└─
1389    have C : compact (f '' K) := this.image f_cont,
id              └─────┘   └┘      └────────┘ └────┘
src    └───────┘└─────┘  └┘ └───┘└────────┘
typ    └───────┘└─────┘ └┘└───┘└────────┘└────┘
doc    └───────┘└─────┘     └───┘          
txt    └───────┘            └───┘          
par    └───────┘            └───┘          
pid    └────┘└─┘            └──┘          
st   ───────────────────────────────────────────────┘└─
1390    have : f '' K = closed_ball x₀ r,
id                  └─────────┘ └┘ 
src    └─────┘    └─────────┘  
typ    └─────┘  └─────────┘└┘
doc    └─────┘     └─────────┘  
txt    └─────┘                  
par    └─────┘                  
pid    └───┘└┘                  
st   ─────────────────────────────────┘
1391      by { rw image_preimage_eq_of_subset, rw hf, exact subset_univ _ },
id               └─────────────────────────┘     └┘        └─────────┘
src           └─┘└─────────────────────────┘  └─┘    └────┘└─────────┘└─┘
typ           └─┘└─────────────────────────┘  └─┘└┘  └────┘└─────────┘└─┘
doc           └─┘                             └─┘    └────┘           └─┘
txt           └─┘                             └─┘    └────┘           └─┘
par           └─┘                             └─┘    └────┘           └─┘
pid                                                                └┘
st          └─────────────────────────────┘└─────┘└────────────────────┘└┘
1392    rwa this at C
id         └──┘
src    └──┘    └────┘
typ    └──┘└──┘└────┘
doc    └──┘    └────┘
txt    └──┘    └────┘
par    └──┘    └────┘
pid           └───┘
st   ───────────────┘
1393  end
st   └─┘
1394  
1395  end bounded
1396  
1397  section diam
1398  variables {s : set α} {x y z : α}
id                  └─┘
src                 └─┘
typ                 └─┘
1399  
1400  /-- The diameter of a set in a metric space. To get controllable behavior even when the diameter
1401  should be infinite, we express it in terms of the emetric.diameter -/
1402  def diam (s : set α) : ℝ := ennreal.to_real (emetric.diam s)
id                 └─┘         └─────────────┘  └──────────┘ 
src                └─┘          └─────────────┘  └──────────┘
typ                └─┘         └─────────────┘  └──────────┘ 
doc                              └─────────────┘  └──────────┘
1403  
1404  /-- The diameter of a set is always nonnegative -/
1405  lemma diam_nonneg : 0 ≤ diam s := ennreal.to_real_nonneg
id                          └──┘     └────────────────────┘
src                         └──┘      └────────────────────┘
typ                         └──┘     └────────────────────┘
doc                          └──┘
1406  
1407  lemma diam_subsingleton (hs : s.subsingleton) : diam s = 0 :=
id                                 └───────────┘    └──┘  
src                                 └───────────┘    └──┘   
typ                                └───────────┘    └──┘  
doc                                 └───────────┘    └──┘
1408  by simp only [diam, emetric.diam_subsingleton hs, ennreal.zero_to_real]
id                 └──┘  └───────────────────────┘ └┘  └──────────────────┘
src     └─────────┘└──┘└┘└───────────────────────┘  └┘└──────────────────┘└─
typ     └─────────┘└──┘└┘└───────────────────────┘└┘└┘└──────────────────┘└─
doc     └─────────┘└──┘└┘└───────────────────────┘  └┘                    └─
txt     └─────────┘    └┘                           └┘                    └─
par     └─────────┘    └┘                           └┘                    └─
pid         └──┘└┘    └┘                           └┘                    
st     └─────────────────────────────────────────────────────────────────────
1409  
src  
typ  
doc  
txt  
par  
pid  
st   
1410  /-- The empty set has zero diameter -/
1411  @[simp] lemma diam_empty : diam (∅ : set α) = 0 :=
id                              └──┘     └─┘   
src                             └──┘     └─┘    
typ                             └──┘     └─┘   
doc    └──┘                     └──┘
1412  diam_subsingleton subsingleton_empty
id   └───────────────┘ └────────────────┘
src  └───────────────┘ └────────────────┘
typ  └───────────────┘ └────────────────┘
1413  
1414  /-- A singleton has zero diameter -/
1415  @[simp] lemma diam_singleton : diam ({x} : set α) = 0 :=
id                                  └──┘      └─┘   
src                                 └──┘       └─┘    
typ                                 └──┘      └─┘   
doc    └──┘                         └──┘
1416  diam_subsingleton subsingleton_singleton
id   └───────────────┘ └────────────────────┘
src  └───────────────┘ └────────────────────┘
typ  └───────────────┘ └────────────────────┘
1417  
1418  @[simp] lemma diam_pair : diam ({x, y} : set α) = dist x y :=
id                             └──┘       └─┘    └──┘  
src                            └──┘         └─┘     └──┘
typ                            └──┘       └─┘    └──┘  
doc    └──┘                    └──┘
1419  by simp only [diam, emetric.diam_pair, dist_edist]
id                 └──┘  └───────────────┘  └────────┘
src     └─────────┘└──┘└┘└───────────────┘└┘└────────┘└─
typ     └─────────┘└──┘└┘└───────────────┘└┘└────────┘└─
doc     └─────────┘└──┘└┘                 └┘└────────┘└─
txt     └─────────┘    └┘                 └┘          └─
par     └─────────┘    └┘                 └┘          └─
pid         └──┘└┘    └┘                 └┘          
st     └────────────────────────────────────────────────
1420  
src  
typ  
doc  
txt  
par  
pid  
st   
1421  @[simp] lemma diam_triple :
doc    └──┘
1422    metric.diam ({x, y, z} : set α) = max (dist x y) (max (dist y z) (dist x z)) :=
id     └─────────┘        └─┘    └─┘  └──┘     └─┘  └──┘     └──┘  
src    └─────────┘           └─┘     └─┘  └──┘       └─┘  └──┘       └──┘
typ    └─────────┘        └─┘    └─┘  └──┘     └─┘  └──┘     └──┘  
doc    └─────────┘
1423  begin
st   └─────
1424    simp only [metric.diam, emetric.diam_triple, dist_edist],
id                └─────────┘  └─────────────────┘  └────────┘
src    └─────────┘└─────────┘└┘└─────────────────┘└┘└────────┘
typ    └─────────┘└─────────┘└┘└─────────────────┘└┘└────────┘
doc    └─────────┘└─────────┘└┘                   └┘└────────┘
txt    └─────────┘           └┘                   └┘          
par    └─────────┘           └┘                   └┘          
pid        └──┘└┘           └┘                   └┘          
st   ─────────────────────────────────────────────────────────┘└─
1425    rw [ennreal.to_real_max, ennreal.to_real_max];
id         └─────────────────┘  └─────────────────┘
src    └──┘└─────────────────┘└┘└─────────────────┘
typ    └──┘└─────────────────┘└┘└─────────────────┘
doc    └──┘                   └┘                   
txt    └──┘                   └┘                   
par    └──┘                   └┘                   
pid      └┘                   └┘                   
st   ────────────────────────┘└───────────────────┘└─
1426      apply_rules [ne_of_lt, edist_lt_top, max_lt]
id                    └──────┘  └──────────┘  └────┘
src      └───────────┘└──────┘└┘└──────────┘└┘└────┘└┘
typ      └───────────┘└──────┘└┘└──────────┘└┘└────┘└┘
doc      └───────────┘        └┘└──────────┘└┘      └┘
txt      └───────────┘        └┘            └┘      └┘
par      └───────────┘        └┘            └┘      └┘
pid                 └┘        └┘            └┘      
st   ────────────────────────────────────────────────┘
1427  end
st   └─┘
1428  
1429  /-- If the distance between any two points in a set is bounded by some constant `C`,
1430  then `ennreal.of_real C`  bounds the emetric diameter of this set. -/
1431  lemma ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
id                                                              └──┘    
src                                                                  └──┘     
typ                                                             └──┘    
1432    emetric.diam s ≤ ennreal.of_real C :=
id     └──────────┘   └─────────────┘ 
src    └──────────┘    └─────────────┘
typ    └──────────┘   └─────────────┘ 
doc    └──────────┘     └─────────────┘
1433  emetric.diam_le_of_forall_edist_le $
id   └────────────────────────────────┘
src  └────────────────────────────────┘
typ  └────────────────────────────────┘
doc  └────────────────────────────────┘
1434  λ x hx y hy, (edist_dist x y).symm ▸ ennreal.of_real_le_of_real (h x hx y hy)
id      └┘  └┘   └────────┘   └──┘   └────────────────────────┘    └┘  └┘
src                └────────┘     └──┘   └────────────────────────┘
typ     └┘  └┘   └────────┘   └──┘   └────────────────────────┘    └┘  └┘
1435  
1436  /-- If the distance between any two points in a set is bounded by some non-negative constant,
1437  this constant bounds the diameter. -/
1438  lemma diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
id                                                                        └──┘    
src                                                                             └──┘     
typ                                                                       └──┘    
1439    diam s ≤ C :=
id     └──┘   
src    └──┘   
typ    └──┘   
doc    └──┘
1440  ennreal.to_real_le_of_le_of_real h₀ (ediam_le_of_forall_dist_le h)
id   └──────────────────────────────┘ └┘  └────────────────────────┘ 
src  └──────────────────────────────┘     └────────────────────────┘
typ  └──────────────────────────────┘ └┘  └────────────────────────┘ 
doc                                       └────────────────────────┘
1441  
1442  /-- If the distance between any two points in a nonempty set is bounded by some constant,
1443  this constant bounds the diameter. -/
1444  lemma diam_le_of_forall_dist_le_of_nonempty (hs : s.nonempty) {C : ℝ}
id                                                     └───────┘       
src                                                     └───────┘       
typ                                                    └───────┘       
doc                                                     └───────┘
1445    (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) : diam s ≤ C :=
id                        └──┘        └──┘   
src                            └──┘           └──┘   
typ                       └──┘        └──┘   
doc                                            └──┘
1446  have h₀ : 0 ≤ C, from let ⟨x, hx⟩ := hs in le_trans dist_nonneg (h x hx x hx),
id                       └─┘    └┘     └┘    └──────┘ └─────────┘  
src                                            └──────┘ └─────────┘
typ                      └─┘    └┘     └┘    └──────┘ └─────────┘  
1447  diam_le_of_forall_dist_le h₀ h
id   └───────────────────────┘ └┘ 
src  └───────────────────────┘
typ  └───────────────────────┘ └┘ 
doc  └───────────────────────┘
1448  
1449  /-- The distance between two points in a set is controlled by the diameter of the set. -/
1450  lemma dist_le_diam_of_mem' (h : emetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) :
id                                   └──────────┘                       
src                                  └──────────┘                          
typ                                  └──────────┘                       
doc                                  └──────────┘
1451    dist x y ≤ diam s :=
id     └──┘    └──┘ 
src    └──┘      └──┘
typ    └──┘    └──┘ 
doc               └──┘
1452  begin
st   └─────
1453    rw [diam, dist_edist],
id         └──┘  └────────┘
src    └──┘└──┘└┘└────────┘
typ    └──┘└──┘└┘└────────┘
doc    └──┘└──┘└┘└────────┘
txt    └──┘    └┘          
par    └──┘    └┘          
pid      └┘    └┘          
st   ─────────┘└──────────┘└──
1454    rw ennreal.to_real_le_to_real (edist_ne_top _ _) h,
id        └────────────────────────┘  └──────────┘      
src    └─┘└────────────────────────┘ └──────────┘└────┘
typ    └─┘└────────────────────────┘ └──────────┘└────┘
doc    └─┘                           └──────────┘└────┘
txt    └─┘                                       └────┘
par    └─┘                                       └────┘
pid                                             └────┘
st   ───────────────────────────────────────────────────┘└─
1455    exact emetric.edist_le_diam_of_mem hx hy
id           └──────────────────────────┘ └┘ └┘
src    └────┘└──────────────────────────┘    
typ    └────┘└──────────────────────────┘└┘└┘
doc    └────┘└──────────────────────────┘    
txt    └────┘                                
par    └────┘                                
pid                                         
st   ──────────────────────────────────────────┘
1456  end
st   └─┘
1457  
1458  /-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/
1459  lemma bounded_iff_ediam_ne_top : bounded s ↔ emetric.diam s ≠ ⊤ :=
id                                    └─────┘   └──────────┘   
src                                   └─────┘    └──────────┘    
typ                                   └─────┘   └──────────┘   
doc                                   └─────┘     └──────────┘
1460  iff.intro
id   └───────┘
src  └───────┘
typ  └───────┘
1461    (λ ⟨C, hC⟩, ne_top_of_le_ne_top ennreal.of_real_ne_top
id           └┘   └─────────────────┘ └────────────────────┘
src                └─────────────────┘ └────────────────────┘
typ          └┘   └─────────────────┘ └────────────────────┘
1462      (ediam_le_of_forall_dist_le $ λ x hx y hy, hC x y hx hy))
id        └────────────────────────┘      └┘  └┘       └┘ └┘
src       └────────────────────────┘
typ       └────────────────────────┘      └┘  └┘       └┘ └┘
doc       └────────────────────────┘
1463    (λ h, ⟨diam s, λ x y hx hy, dist_le_diam_of_mem' h hx hy⟩)
id           └──┘       └┘ └┘  └──────────────────┘  └┘ └┘
src           └──┘                 └──────────────────┘
typ          └──┘       └┘ └┘  └──────────────────┘  └┘ └┘
doc           └──┘                 └──────────────────┘
1464  
1465  lemma bounded.ediam_ne_top (h : bounded s) : emetric.diam s ≠ ⊤ :=
id                                   └─────┘     └──────────┘   
src                                  └─────┘      └──────────┘    
typ                                  └─────┘     └──────────┘   
doc                                  └─────┘      └──────────┘
1466  bounded_iff_ediam_ne_top.1 h
id   └──────────────────────┘  
src  └──────────────────────┘
typ  └──────────────────────┘  
doc  └──────────────────────┘
1467  
1468  /-- The distance between two points in a set is controlled by the diameter of the set. -/
1469  lemma dist_le_diam_of_mem (h : bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=
id                                  └─────┘                         └──┘    └──┘ 
src                                 └─────┘                              └──┘      └──┘
typ                                 └─────┘                         └──┘    └──┘ 
doc                                 └─────┘                                           └──┘
1470  dist_le_diam_of_mem' h.ediam_ne_top hx hy
id   └──────────────────┘ └───────────┘ └┘ └┘
src  └──────────────────┘  └───────────┘
typ  └──────────────────┘ └───────────┘ └┘ └┘
doc  └──────────────────┘
1471  
1472  /-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`.
1473  This lemma makes it possible to avoid side conditions in some situations -/
1474  lemma diam_eq_zero_of_unbounded (h : ¬(bounded s)) : diam s = 0 :=
id                                         └─────┘      └──┘  
src                                        └─────┘       └──┘   
typ                                        └─────┘      └──┘  
doc                                         └─────┘       └──┘
1475  begin
st   └─────
1476    simp only [bounded_iff_ediam_ne_top, not_not, ne.def] at h,
id                └──────────────────────┘  └─────┘  └────┘
src    └─────────┘└──────────────────────┘└┘└─────┘└┘└────┘└────┘
typ    └─────────┘└──────────────────────┘└┘└─────┘└┘└────┘└────┘
doc    └─────────┘└──────────────────────┘└┘       └┘      └────┘
txt    └─────────┘                        └┘       └┘      └────┘
par    └─────────┘                        └┘       └┘      └────┘
pid        └──┘└┘                        └┘       └┘      └──┘
st   ───────────────────────────────────────────────────────────┘└─
1477    simp [diam, h]
id           └──┘  
src    └────┘└──┘└┘ └┘
typ    └────┘└──┘└┘└┘
doc    └────┘└──┘└┘ └┘
txt    └────┘    └┘ └┘
par    └────┘    └┘ └┘
pid            └┘ 
st   ────────────────┘
1478  end
st   └─┘
1479  
1480  /-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/
1481  lemma diam_mono {s t : set α} (h : s ⊆ t) (ht : bounded t) : diam s ≤ diam t :=
id                          └─┘                  └─────┘     └──┘   └──┘ 
src                         └─┘                     └─────┘      └──┘    └──┘
typ                         └─┘                  └─────┘     └──┘   └──┘ 
doc                                                  └─────┘      └──┘     └──┘
1482  begin
st   └─────
1483    unfold diam,
src    └─────────┘
typ    └─────────┘
doc    └─────────┘
txt    └─────────┘
par    └─────────┘
pid          └───┘
st   ────────────┘└─
1484    rw ennreal.to_real_le_to_real (bounded.subset h ht).ediam_ne_top ht.ediam_ne_top,
id        └────────────────────────┘  └────────────┘                   └─────────────┘
src    └─┘└────────────────────────┘ └────────────┘   └─────────────┘└─────────────┘
typ    └─┘└────────────────────────┘ └────────────┘  └─────────────┘└─────────────┘
doc    └─┘                           └────────────┘   └─────────────┘
txt    └─┘                                            └─────────────┘
par    └─┘                                            └─────────────┘
pid                                                  └─────────────┘
st   ─────────────────────────────────────────────────────────────────────────────────┘└─
1485    exact emetric.diam_mono h
id           └───────────────┘ 
src    └────┘└───────────────┘ 
typ    └────┘└───────────────┘
doc    └────┘└───────────────┘ 
txt    └────┘                  
par    └────┘                  
pid                           
st   ───────────────────────────┘
1486  end
st   └─┘
1487  
1488  /-- The diameter of a union is controlled by the sum of the diameters, and the distance between
1489  any two points in each of the sets. This lemma is true without any side condition, since it is
1490  obviously true if `s ∪ t` is unbounded. -/
1491  lemma diam_union {t : set α} (xs : x ∈ s) (yt : y ∈ t) : diam (s ∪ t) ≤ diam s + dist x y + diam t :=
id                         └─┘                         └──┘       └──┘   └──┘    └──┘ 
src                        └─┘                              └──┘         └──┘    └──┘      └──┘
typ                        └─┘                         └──┘       └──┘   └──┘    └──┘ 
doc                                                           └──┘           └──┘                └──┘
1492  begin
st   └─────
1493    classical, by_cases H : bounded (s ∪ t),
id                             └─────┘    
src    └───────┘  └───────┘ └─┘└─────┘   
typ    └───────┘  └───────┘ └─┘└─────┘ 
doc    └───────┘  └───────┘ └─┘└─────┘    
txt    └───────┘  └───────┘ └─┘           
par    └───────┘  └───────┘ └─┘           
pid                        └─┘           
st   ──────────┘└────────────────────────────┘└─
1494    { have hs : bounded s, from H.subset (subset_union_left _ _),
id                 └─────┘        └──────┘  └───────────────┘
src      └────────┘└─────┘   └───┘└──────┘ └───────────────┘└───┘
typ      └────────┘└─────┘  └───┘└──────┘ └───────────────┘└───┘
doc      └────────┘└─────┘   └───┘└──────┘                  └───┘
txt      └────────┘          └───┘                          └───┘
par      └────────┘          └───┘                          └───┘
pid      └─────┘└─┘          └───┘                          └───┘
st   ───┘└─────────────────┘└─────────────────────────────────────┘└─
1495      have ht : bounded t, from H.subset (subset_union_right _ _),
id                 └─────┘        └──────┘  └────────────────┘
src      └────────┘└─────┘   └───┘└──────┘ └────────────────┘└───┘
typ      └────────┘└─────┘  └───┘└──────┘ └────────────────┘└───┘
doc      └────────┘└─────┘   └───┘└──────┘                   └───┘
txt      └────────┘          └───┘                           └───┘
par      └────────┘          └───┘                           └───┘
pid      └─────┘└─┘          └───┘                           └───┘
st   ──────────────────────┘└──────────────────────────────────────┘└─
1496      rw [bounded_iff_ediam_ne_top] at H hs ht,
id           └──────────────────────┘
src      └──┘└──────────────────────┘└──────────┘
typ      └──┘└──────────────────────┘└──────────┘
doc      └──┘└──────────────────────┘└──────────┘
txt      └──┘                        └──────────┘
par      └──┘                        └──────────┘
pid        └┘                        └─────────┘
st   ───────────────────────────────┘└─────────┘└─
1497      rw [dist_edist, diam, diam, diam, ← ennreal.to_real_add, ← ennreal.to_real_add,
id           └────────┘  └──┘  └──┘  └──┘    └─────────────────┘    └─────────────────┘
src      └──┘└────────┘└┘└──┘└┘└──┘└┘└──┘└──┘└─────────────────┘└──┘└─────────────────┘└─
typ      └──┘└────────┘└┘└──┘└┘└──┘└┘└──┘└──┘└─────────────────┘└──┘└─────────────────┘└─
doc      └──┘└────────┘└┘└──┘└┘└──┘└┘└──┘└──┘                   └──┘                   └─
txt      └──┘          └┘    └┘    └┘    └──┘                   └──┘                   └─
par      └──┘          └┘    └┘    └┘    └──┘                   └──┘                   └─
pid        └┘          └┘    └┘    └┘    └──┘                   └──┘                   └─
st   ─────────────────┘└────┘└────┘└────┘└─────────────────────┘└─────────────────────┘└─
1498        ennreal.to_real_le_to_real];
id         └────────────────────────┘
src  ─────┘└────────────────────────┘
typ  ─────┘└────────────────────────┘
doc  ─────┘                          
txt  ─────┘                          
par  ─────┘                          
pid  ─────┘                          
st   ───────────────────────────────┘└─
1499        repeat { apply ennreal.add_ne_top.2; split }; try { assumption };
id                        └────────────────┘
src        └───────┘└────┘└────────────────┘└┘└┘└────┘  └────┘└─────────┘
typ        └───────┘└────┘└────────────────┘└┘└┘└────┘  └────┘└─────────┘
doc        └───────┘└────┘                  └┘└┘└────┘  └────┘└─────────┘
txt        └───────┘└────┘                  └┘└┘└────┘  └────┘└─────────┘
par        └───────┘└────┘                  └┘└┘└────┘  └────┘└─────────┘
pid              └───────┘                  └─────────┘     └─────────────┘
st   ─────────────┘└─────────────────────────────────┘└┘└────┘└──────────┘└┘
1500        try { apply edist_ne_top },
id                     └──────────┘
src        └────┘└────┘└──────────┘
typ        └────┘└────┘└──────────┘
doc        └────┘└────┘└──────────┘
txt        └────┘└────┘            
par        └────┘└────┘            
pid           └───────┘            └┘
st   ──────────┘└──────────────────┘└┘
1501      exact emetric.diam_union xs yt },
id             └────────────────┘ └┘ └┘
src      └────┘└────────────────┘    
typ      └────┘└────────────────┘└┘└┘
doc      └────┘└────────────────┘    
txt      └────┘                      
par      └────┘                      
pid                                 
st   ──────────────────────────────────┘└┘
1502    { rw [diam_eq_zero_of_unbounded H],
id           └───────────────────────┘ 
src      └──┘└───────────────────────┘ 
typ      └──┘└───────────────────────┘
doc      └──┘└───────────────────────┘ 
txt      └──┘                          
par      └──┘                          
pid        └┘                          
st   ──────────────────────────────────┘└──
1503      apply_rules [add_nonneg, diam_nonneg, dist_nonneg] }
id                    └────────┘  └─────────┘  └─────────┘
src      └───────────┘└────────┘└┘└─────────┘└┘└─────────┘└┘
typ      └───────────┘└────────┘└┘└─────────┘└┘└─────────┘└┘
doc      └───────────┘          └┘└─────────┘└┘           └┘
txt      └───────────┘          └┘           └┘           └┘
par      └───────────┘          └┘           └┘           └┘
pid                 └┘          └┘           └┘           
st   ──────────────────────────────────────────────────────┘└─
1504  end
st   ──┘
1505  
1506  /-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/
1507  lemma diam_union' {t : set α} (h : (s ∩ t).nonempty) : diam (s ∪ t) ≤ diam s + diam t :=
id                          └─┘            └──────┘     └──┘       └──┘   └──┘ 
src                         └─┘               └──────┘     └──┘         └──┘    └──┘
typ                         └─┘            └──────┘     └──┘       └──┘   └──┘ 
doc                                            └──────┘     └──┘           └──┘     └──┘
1508  begin
st   └─────
1509    rcases h with ⟨x, ⟨xs, xt⟩⟩,
id            
src    └─────┘ └─────────────────┘
typ    └─────┘└─────────────────┘
doc    └─────┘ └─────────────────┘
txt    └─────┘ └─────────────────┘
par    └─────┘ └─────────────────┘
pid           └─────────────────┘
st   ────────────────────────────┘└─
1510    simpa using diam_union xs xt
id                 └────────┘ └┘ └┘
src    └──────────┘└────────┘    
typ    └──────────┘└────────┘└┘└┘
doc    └──────────┘└────────┘    
txt    └──────────┘              
par    └──────────┘              
pid         └────┘              
st   ──────────────────────────────┘
1511  end
st   └─┘
1512  
1513  /-- The diameter of a closed ball of radius `r` is at most `2 r`. -/
1514  lemma diam_closed_ball {r : ℝ} (h : r ≥ 0) : diam (closed_ball x r) ≤ 2 * r :=
id                                             └──┘  └─────────┘        
src                                             └──┘  └─────────┘         
typ                                            └──┘  └─────────┘        
doc                                               └──┘  └─────────┘
1515  diam_le_of_forall_dist_le (mul_nonneg (le_of_lt two_pos) h) $ λa ha b hb, calc
id   └───────────────────────┘  └────────┘  └──────┘ └─────┘        └┘  └┘
src  └───────────────────────┘  └────────┘  └──────┘ └─────┘
typ  └───────────────────────┘  └────────┘  └──────┘ └─────┘        └┘  └┘
doc  └───────────────────────┘
1516    dist a b ≤ dist a x + dist b x : dist_triangle_right _ _ _
id     └──┘     └──┘    └──┘     └─────────────────┘
src    └──┘       └──┘      └──┘       └─────────────────┘
typ    └──┘     └──┘    └──┘     └─────────────────┘
1517    ... ≤ r + r : add_le_add ha hb
id                └────────┘ └┘ └┘
src                 └────────┘
typ               └────────┘ └┘ └┘
1518    ... = 2 * r : by simp [mul_two, mul_comm]
id                          └─────┘  └──────┘
src                    └────┘└─────┘└┘└──────┘└─
typ                   └────┘└─────┘└┘└──────┘└─
doc                     └────┘       └┘        └─
txt                     └────┘       └┘        └─
par                     └────┘       └┘        └─
pid                                └┘        
st                     └─────────────────────────
1519  
src  
typ  
doc  
txt  
par  
pid  
st   
1520  /-- The diameter of a ball of radius `r` is at most `2 r`. -/
1521  lemma diam_ball {r : ℝ} (h : r ≥ 0) : diam (ball x r) ≤ 2 * r :=
id                                      └──┘  └──┘        
src                                      └──┘  └──┘         
typ                                     └──┘  └──┘        
doc                                        └──┘  └──┘
1522  le_trans (diam_mono ball_subset_closed_ball bounded_closed_ball) (diam_closed_ball h)
id   └──────┘  └───────┘ └─────────────────────┘ └─────────────────┘   └──────────────┘ 
src  └──────┘  └───────┘ └─────────────────────┘ └─────────────────┘   └──────────────┘
typ  └──────┘  └───────┘ └─────────────────────┘ └─────────────────┘   └──────────────┘ 
doc            └───────┘                         └─────────────────┘   └──────────────┘
1523  
1524  end diam
1525  
1526  end metric